<p>Have you tried something like:</p>

<pre><code>&lt;li class="{{ page.getChildren()|length == 0 ? 'dropdown-item' : 'dropdown-submenu' }}"&gt;
</code></pre>

<p>If that doesn't work, I suspect you could use {% ifchildren %} in concert with a variable to set the style. In this case, we set the variable to a non-null value if there are children. Then we can use the null-coalescing operator to substitute 'dropdown-item' if there are no children. Like:</p>

<pre><code>{% set listclass = null %}
{% ifchildren %}
    {% set listclass = 'dropdown-submenu' %}
{% endifchildren% }
&lt;li class="{{ listclass ?? 'dropdown-item' }}"&gt;
</code></pre>

CC BY-SA 3.0
2018-04-26T21:35:40.543Z
First one did the trick.  Thanks so much!
fodney
CC BY-SA 3.0
2018-04-26T21:14:26.873Z
2018-04-26T21:14:26.873Z
Nik Shenoy
<p>On the menu below I need to change the class on the li from dropdown-submenu to dropdown-item for those entries that don't have children.  Any ideas?</p>

<p>Thanks</p>

<pre><code>{% set pages = craft.entries.section('services') %}
                       {% nav page in pages %}
           &lt;li class="dropdown-submenu"&gt; 
                {{ page.getLink() }}

                {% ifchildren %}
                   &lt;ul class="dropdown-menu" aria-labelledby="dropdownMenuLink"&gt;
                        {% children %}
                    &lt;/ul&gt;
                {% endifchildren %}
            &lt;/li&gt;

        {% endnav %}
</code></pre>

<navigation>
Conditional statement for nav tag when no children
# Conditional statement for nav tag when no children

(Asked by: username_0 on 2018-04-26)

On the menu below I need to change the class on the li from dropdown-submenu to dropdown-item for those entries that don't have children.  Any ideas?
Thanks
{% set pages = craft.entries.section('services') %}
                       {% nav page in pages %}
            
                {{ page.getLink() }}

                {% ifchildren %}
                   
                        {% children %}
                    
                {% endifchildren %}
            

        {% endnav %}

**Tags:** navigation

---

## 1 answers

### Answer by username_1 on 2018-04-26. Score: 0 | Accepted answer

Have you tried something like:


If that doesn't work, I suspect you could use {% ifchildren %} in concert with a variable to set the style. In this case, we set the variable to a non-null value if there are children. Then we can use the null-coalescing operator to substitute 'dropdown-item' if there are no children. Like:
{% set listclass = null %}
{% ifchildren %}
    {% set listclass = 'dropdown-submenu' %}
{% endifchildren% }

> **Comments:**
> **username_0**: First one did the trick.  Thanks so much!  

---

