How to hide form fields in twig template?
问题 I have a Symfony form that includes two TextType fields. If a certain check evaluates to false , I don't want to display the input fields but output the static content of the field and include the form fields as hidden fields instead. How can I do that? 回答1: you can use HiddenType , or hide field in template: {{ form_start(form) }} {% if someValue == true %} {{ form_widget(form.fieldName) }} {% else %} {{ form_widget(form.fieldName, { 'attr': {'class': 'hidden-row'} }) }} {% endif %} {# other