Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set choice values in twig? #18950

Closed
dialogik opened this issue Jun 2, 2016 · 2 comments
Closed

How to set choice values in twig? #18950

dialogik opened this issue Jun 2, 2016 · 2 comments
Labels

Comments

@dialogik
Copy link

dialogik commented Jun 2, 2016

I am using a ChoiceType in a Symfony3 form type

$builder
    ->add('confirmation', ChoiceType::class, array(
        'choices'  => array(
            'Maybe' => null,
            'Yes' => true,
            'No' => false,
        )
))

Now I want to set choices dynamically in twig. I would assume to go like this

{{ form_widget(field.type, {'choices': {'foo': true, 'bar': false}}) }}

but that throws error

Impossible to access an attribute ("attr") on a boolean variable ("1") in form_div_layout.html.twig at line 82

Is there any way to set choices in twig (while rendering the form field using form_widget() or form_row())?

@stof
Copy link
Member

stof commented Jun 2, 2016

no you cannot, because choices impact the building of the form. They are not passed as is to the template (they main goal of the Form component is not to handle the rendering, but to handle the form binding)

@javiereguiluz
Copy link
Member

Closing this issue because, apparently, this "limitation" is instead a "feature".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants