title: Get number of choices from entity field in Twig template
body: <p>I have a Symfony 2 form for a Doctrine entity with an entity choice field for a ManyToMany relationship. It is possible for the choice field to not have any choices - how can I test for this in Twig?</p>
  
  <p>Example: The form is for a "Deal" entity, which can optionally be assigned to a "Location" entity. I render the "Location" entity field like this:</p>
  
  <pre><code>{{ form_label(edit_form.locations) }}
  {{ form_errors(edit_form.locations) }}
  {{ form_widget(edit_form.locations) }}
  </code></pre>
  
  <p>The field is set to render with checkboxes. However, it is possible that no "Location" records will exist. In this scenario the user will see the label "Locations: " but no check boxes. I would like to have a conditional statement that displays a message, something along the lines of this:</p>
  
  <pre><code>{{ form_label(edit_form.locations) }}
  {{ form_errors(edit_form.locations) }}
  {{ form_widget(edit_form.locations) }}
  {% if edit_form.locations.choices|length == 0 %}
    You haven't created any Locations yet!
  {% endif %}
  </code></pre>
  
  <p>Anybody know of a way to achieve this?</p>