Twig variable in form_row(form.form, 'attr':{'value':var})



我尝试在 form_row() 中制作变量

{{ form_start(genusForm) }}
{{ form_row(genusForm.speciesCount, {
'label': variable
}) }}
{{ form_end(genusForm) }}

我试过{{ variable },不起作用。

form_row返回标签、输入和错误块因此,如果要为标签添加属性,则应使用form_label

{{ form_label(genusForm.speciesCount, { 'attr': {'name-attr': variable}} ) }}

https://symfony.com/doc/current/reference/forms/twig_reference.html#form-label-view-label-variables

最新更新