0

How to display a zend-form element select in twig template? Do as follows:

Form:

$this->add([
    'name'    => 'parent',
    'type' => 'Zend\Form\Element\Select',
    'options' => [
        'label' => 'Принадлежность',
        'empty_option' => 'Выберите категорию',
        'value_options' => [
            '0' => 'French',
            '1' => 'English',
            '2' => 'Japanese',
            '3' => 'Chinese',
        ],
    ],
]);

Twig:

<div class="form-group select">
     <label for="{{ form.get('parent').name }}">{{ form.get('parent').label }}</label>
     <select class="form-control" type="{{ form.get('parent').attributes.type }}" name="{{ form.get('parent').name }}">
         <option>{{ form.get('parent').options.value_options }}</option>
    </select>
</div>
Drakulitka
  • 41
  • 6

1 Answers1

0

You should be able to achieve it with something like this:

<div class="form-group select">
     <label for="{{ form.get('parent').name }}">{{ form.get('parent').label }}</label>
     <select class="form-control" type="{{ form.get('parent').attributes.type }}" name="{{ form.get('parent').name }}">
        {% for option in form.get('parent').options.value_options %} 
        <option>{{ option }}</option>
        {% endfor %}
    </select>
</div>

Since I haven't used twing I can't be sure.
Read more about twig for loop here.