symfony2.1: count doctrine collection in twig template
doctrine-orm, php, symfony-2.1, templates, twig
Solution
As found here, with doctrine there is the option to use the "count" method when handling a doctrine collection. Otherwise you can use the "length" Filter.
Example Code:
<ul class="summary">
<li> {{ object.children | length }}</li>
<!-- or, use the count method of doctrine collections directly -->
<li> {{ object.children.count }}</li>
</ul>
Problem
I have a doctrine entity that has a collection of entities (children). Now i want to count the entities and print out the count. Something like this: ``` <div class="item"> <h1>{{ object.name }}</h1> <div class="childrenCount">children {% count (object.children) %}</div> </div> ``` I found some examples which didn't work (like using a "count" filter which resulted in a "filter not found" error).