Reputation: 910
I am new in Symfony2 and try to render a form. The basics are clear, but I have a problem with hidden form fields.
I try to render each form widget in a different table cell. But when using a for loop, the first cell is filled with the _token widget. But I like to render the hidden fields afterwards with form_rest.
<table>
<tr>
{% for element in form %}
<td class="header">{{ form_widget(element) }} </td>
{% endfor %}
</tr>
</table>
What I am looking for is something like
<table>
<tr>
{% for element in form %}
{% if element.type != 'hidden' %}
<td class="header">{{ form_widget(element) }} </td>
{% endif %}
{% endfor %}
</tr>
</table>
Can anyone help me with that? Thanks a lot.
Upvotes: 1
Views: 4129
Reputation: 51
For Symfony 2.0 you used to do:
{% if "hidden" not in element.vars.types %}
For Symfony 2.1 you've got to do:
{% if "hidden" not in element.vars.block_prefixes %}
It took me ages to work this out because there is no documentation about it at all. I'm also bemused as to why you can't just do:
{% if "hidden" element.vars.type %}
I mean, isn't this the most obvious way?
Upvotes: 5
Reputation: 120
Try this:
<table>
<tr>
{% for element in form %}
{% if "hidden" not in element.vars.types %}
<td class="header">{{ form_widget(element) }} </td>
{% endif %}
{% endfor %}
</tr>
</table>
Upvotes: 0
Reputation: 4441
Try this below code
<table>
<tr>
{% for element in form %}
{% if not element.ishidden %}
<td class="header">{{ form_widget(element) }} </td>
{% endif %}
{% endfor %}
</tr>
</table>
Hope this helps you. Happy coding!!!
Upvotes: 2
Reputation: 1710
A bit of a shot in the dark, but maybe you can use the label in the if statement?
Sort of like {% if form_label(element) != "hidden" %}?
Upvotes: 0