Symfony2 Twig Get Total Count for Child Entity

前端 未结 2 1906
臣服心动
臣服心动 2021-01-22 13:47

The following entities exist, Farm, Barn and Animals. A Farm can have many Barns and a Barn many Animals.

When displaying a Farm in a TWIG template the number of Animals

2条回答
  •  长发绾君心
    2021-01-22 14:27

    You are looking for the length filter

    When used with an array, length will give you the number of items. So, if your array is farm.barns, you can just use {{ farm.barns|length }}

提交回复
热议问题