Directly access a form field's value when overriding widget in a twig template

后端 未结 5 848
清酒与你
清酒与你 2020-12-13 23:42

What I want to do is get variables stored in form view.

{% form_theme edit_form _self %}

{% block field_widget %}
{% spaceless %}
{% set type = type|default         


        
5条回答
  •  执笔经年
    2020-12-13 23:47

    You can access the current data of your form via form.vars.value:

    {{ form.vars.value.title }}
    

    See Symfony2 Forms documentation: http://symfony.com/doc/current/book/forms.html#rendering-a-form-in-a-template

    Dump vars by using dump function:

    {{ dump(form.vars.value) }}
    

    If you are using subforms or want to have a value of a specific field:

    {{ form.FIELD.vars.VALUE }}
    

提交回复
热议问题