-----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 or not...
so what i am going to combine your explanations into something like

{% if entry.children is defined %}
  {% if entry.children|length %}
    children
  {% else %}
    no children
  {% endif %}
{% else %}
  undefined
{% endif %}



Am 16.04.2011 21:35, schrieb John Bohn:
> 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 fall back to the else statement.
> 
> Hope it helps,
> John Bohn
> [email protected]
> 
> On Sat, Apr 16, 2011 at 2:03 PM, Jordi Boggiano <[email protected]> wrote:
>> 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
>> {% else %}
>>  no children
>> {% endif %}
>>
>> If it can be defined and empty, then you can use:
>>
>> {% if entry.children is defined %}
>>  {% for child in entry.children %}
>>    children
>>  {% else %}
>>    no children
>>  {% endfor %}
>> {% endif %}
>>
>> Cheers
>>
>> --
>> Jordi Boggiano
>> @seldaek :: http://seld.be/
>>
>> --
>> 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 [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/symfony-users?hl=en
>>
> 

- -- 
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2qqRIACgkQqBnXnqWBgIt06QCgwspybweqyCvg575Fk5gPdkxC
x24An3L2eYeFDwyzob9i9z+GP7hXBOyg
=3l0a
-----END PGP SIGNATURE-----

-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to