Symfony2 - Twig : Set the default value in the dropdownlist

后端 未结 2 1216
梦谈多话
梦谈多话 2021-01-15 02:45

I have a Form in my twig template. One of the form fields is a dropdownlist that is created from an Entity in my form builder.

I would like to set the default value

相关标签:
2条回答
  • 2021-01-15 03:30

    Ok, found my mistake, the code should be:

    {{ form_widget(form.type, {value: "28" } ) }}
    

    I forgot the quotes for the id. And also, there is a need to CTRL + F5 to refresh the page and see the difference.

    0 讨论(0)
  • 2021-01-15 03:30

    as @Elium1984 suggested

    {{ form_widget(form.type, {value: twig_var ~ "" } ) }} 
    

    or

    {{ form_row(form.type, {value: twig_var ~ "" } ) }} 
    
    0 讨论(0)
提交回复
热议问题