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 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) or we do not > know if there where children because we did not look). my current code > is this (and it fails on the first line. the next line is not good > either, because there is no count() in twig.) > > {% if entry.children %} > {% if count(entry.children) %} > children > {% else %} > nochildren > {% endif %} > {% endif %} > > > http://www.twig-project.org/doc/templates.html#variables > this claims that entry.children would return null if the entry has no > children field, but i get Item "children" for "Array" does not exist > > 1. how to check whether an array field is defined? > 2. how to check whether a variable is a non-empty array? > > cheers, > david > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en