Reputation: 1
I want to duplicate each form row inside my template by using for loop this is my code, but it's doesn't work, it's returned only the first line with form and those other without form, please could somebody help me ?
{% for commande in commandes %}
<tr><td>{{ form_row(form.id, {'attr': 'value': commande.id} ) }}</td></tr>
<tr><td>{{ form_row(form.number, {'attr': 'value': commande.number} ) }}</td></tr>
<tr><td>{{ form_row(form.date, {'attr': 'value': commande.date} ) }}</td>
<td><button type="submit" name="btn">update</td>
</tr>
{% endfor %}
Upvotes: 0
Views: 443
Reputation: 8374
Forms are sometimes smart and know they have been rendered.
Workaround:
{% set output_id = form_row(form.id, {'attr': 'value': commande.id}) %}
{{ output_id }}
and later on you can access it again:
{{ output_id }}
You can also do this for more than a form row (or for adding markup):
{% set output %}
{{ form_row(form.id) }}
{{ form_row(form.number) }}
{{ form_row(form.date) }}
{% endset %}
{{ output }}
(Alternatively, you can probably set the rendered
attribute to false or something, but to be honest, that seems worse to me than capturing the output).
Upvotes: 1