-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
thanks oscar, john and jordi
a cool syntax, the for/else, twig is really useful :-)
actually i need to distinguish whether i have 0 children, 0 children
or the children array is missing, which means the code did not check
whether there where children
Hi. You must use the 'length' filter:
{{ entry|length }}
That must do the trick.
2011/4/13 David Buchmann david.buchm...@liip.ch
hi,
for a symfony2 project, i use twig. i have a template that outputs a
tree (nested php array)
what i try to do is: check if there is a 'children' field on
On 16.04.2011 20:39, oscar balladares wrote:
Hi. You must use the 'length' filter:
{{ entry|length }}
That must do the trick.
That will check the length of the array, if it exists. To check whether
entry.children is there, you need to use:
{% if entry.children is defined %}
children
{%
A nice built in feature of TWIG is the for/else loop. Not sure if it's
exactly what you are looking for it would look like this:
{% for child in entry.children %}
child
{% else %}
no children
{% endfor %}
It will loop the entry.children if it exists and is not empty,
otherwise it will
hi,
for a symfony2 project, i use twig. i have a template that outputs a
tree (nested php array)
what i try to do is: check if there is a 'children' field on the entry,
then if the children list contains at least one entry. (i have 3 cases:
an entry has children, it has no children (empty array)