Steffen Brueckner
Steffen Brueckner

Reputation: 209

Render choice options separately

I have researched quite a bit and also read the documentation but this thing remains unanswered.

I want to render choice-options separately in twig and a {%for%} loop doesn't seem to work.

Here's the situation:

I have 3 radio buttons which are supplemented with 3 different blocks of html each (therefore I cannot do a loop over the segments as they are different).

Form-Extract (form 'payment'):

         array(
                'choices'     => array(
                    'paypal' => 'payment.method.paypal',
                    'bank'   => 'payment.method.bank',
                    'check'  => /** @Ignore */
                ),
                'label'       => 'payment.method',
                'expanded'    => 'true',

How could I access the different choice options in twig? I have tried

{{ form_widget(form.payment.method[bank]) }}

and also

{{ form_widget(form.payment.method.bank) }}

Thanks so much for your help. Stefffen

Upvotes: 0

Views: 1531

Answers (1)

Alexandru Furculita
Alexandru Furculita

Reputation: 1373

You might want do it this way:

{% for method in form.payment %}
    {% if method.vars.value == "paypal" %}
        #Render it in a paypal awesome way
        {{ form_widget(method) }}
        {{ form_label(method) }}
    {% else if method.vars.value == "bank" %}
        #Render it in a bank awesome way
        {{ form_widget(method) }}
        {{ form_label(method) }}
    {% endif %}        
{% endfor %}

Hope it helps

Upvotes: 2

Related Questions