2

I have a Customer object, which has many Emails.

I'm building a form for my customer, and I've added his emails as a collection. In my template, I render the emails portion like this:

<h4>Emails</h4>
{% for email in form.emails %}
  <li>
    {{ form_row(email.addr) }}
    {{ form_row(email.isPrimary) }}
  </li>
{% endfor %}
...
{{ form_rest(form) }}

This works fine, except if the customer has no emails. Then, form_rest() renders the label 'emails' at the bottom of my template.

Why does this only get rendered when form.emails is empty? How can I customize it? (Note I've already customized my label rendering for other form elements, and I don't want it to be the same for these 'collection labels'.)

4

1 回答 1

1

I usually solved this problem this way:

{% for email in form.emails %}
    {# ... #}
{% else %}
    {{ form_widget(form.emails) }}
{% endfor %}

Unless someone suggests a better way of doing this.

于 2013-03-29T20:17:25.870 回答