Structure - Add class if element has children I have a structure section which I am using to create a navigation menu.
It works ok and produces the list etc.
I want to add a class to the li element if it has children.

Current Code is:

{% set entries = craft.entries.section('navigation') %}

&lt;ul&gt;
    {% nav entry in entries %}
        &lt;li&gt;

            {# Check for entry type / get related entry #}
            {% if entry.type == 'customLink' %}

                {# Link to a custom url #}
                &lt;a href="{{ entry.customUrl }}"&gt;{{ entry.title }}&lt;/a&gt;

            {% else %}

                {# Link to a structure entry #}
                &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;

            {% endif %}

            {# Repeat this for child entries #}
            {% ifchildren %}
                &lt;ul class="dropdown"&gt;{% children %}&lt;/ul&gt;
            {% endifchildren %}

        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;


I want to add class="has-dropdown" to the first list element if it has children.

I have tried this:

&lt;li {% ifchildren %}class="has-dropdown"{% endifchildren %}&gt;


But that does not work. How can this be achieved?
The Methods section on the EntryModel documentation page has a lot of useful things for working with navigation for Structure sections. You can use hasDescendants():

{% if entry.hasDescendants() %}class="has-dropdown"{% endif %}