<p>As the children inherit the settings between the {% nav %}...{% endnav %} so to show an active state on a navigation use...</p>

<pre><code>&lt;ul&gt;
    {% nav entry in craft.entries.section('entry') %}                               
        &lt;li class="
            {% if craft.request.getSegment(1) == entry.slug or 
                  craft.request.getSegment(2) == entry.slug %}
                selected
            {% endif %}
            {% if craft.entries.section('entry').descendantOf(entry).find() | length &gt; 0 %}
                has-children
            {% endif %}
        "&gt;
            {{ entry.getLink() }}
            {% ifchildren %}
                &lt;ul&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;
</code></pre>

<p>Or use entry.level to target the different levels if you need to.</p>

CC BY-SA 3.0
2015-11-21T13:56:27.703Z
2015-11-23T06:45:56.420Z
2015-11-23T06:45:56.420Z
Eli Peters
<p>I think you need to set a conditional for the entry level for the parent, which is <code>1</code>.</p>

<pre><code>{% set entries = craft.entries.section('pages') %}

&lt;ul id="nav"&gt;
    {% nav entry in entries %}
        &lt;li{% if entry.level == 1 %} class="whatever"{% endif %}&gt;
            &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
            {% ifchildren %}
                &lt;ul&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2015-02-10T20:46:03.197Z
Thanks Chris. I ended up outputting it with this, a lot of conditionals (because there was more to be changed than i showed for simplicities sake) but it seems to do the trick so it'll work.
Christopher Healey
CC BY-SA 3.0
2015-02-10T20:21:30.643Z
2015-02-10T20:21:30.643Z
Christopher Kennedy-Nuñez
<p>I need to output different HTML for children of navigation. When i use</p>

<pre><code>{% set entries = craft.entries.section('pages') %}

&lt;ul id="nav"&gt;
    {% nav entry in entries %}
        &lt;li class="whatever"&gt;
            &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
            {% ifchildren %}
                &lt;ul&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;
</code></pre>

<p>It outputs my children having class="whatever" as well. I don't want that, i need something else for the children.</p>

<p>I saw the post here: <a href="https://craftcms.stackexchange.com/questions/1733/custom-or-complex-nav-tag">Custom or complex nav tag</a> about using LEVEL however i don't quite understand how i would write the code for that. Could anybody help? Thanks!</p>

<navigation><children>
Complex Navigation
# Complex Navigation

(Asked by: username_0 on 2015-02-10)

I need to output different HTML for children of navigation. When i use
{% set entries = craft.entries.section('pages') %}


    {% nav entry in entries %}
        
            {{ entry.title }}
            {% ifchildren %}
                
                    {% children %}
                
            {% endifchildren %}
        
    {% endnav %}


It outputs my children having class="whatever" as well. I don't want that, i need something else for the children.
I saw the post here: Custom or complex nav tag about using LEVEL however i don't quite understand how i would write the code for that. Could anybody help? Thanks!

**Tags:** navigation, children

---

## 2 answers

### Answer by username_2 on 2015-02-10. Score: 5 | Accepted answer

I think you need to set a conditional for the entry level for the parent, which is 1.
{% set entries = craft.entries.section('pages') %}


    {% nav entry in entries %}
        
            {{ entry.title }}
            {% ifchildren %}
                
                    {% children %}
                
            {% endifchildren %}
        
    {% endnav %}

> **Comments:**
> **username_0**: Thanks Chris. I ended up outputting it with this, a lot of conditionals (because there was more to be changed than i showed for simplicities sake) but it seems to do the trick so it'll work.  

---

### Answer by username_1 on 2015-11-21. Score: 1

As the children inherit the settings between the {% nav %}...{% endnav %} so to show an active state on a navigation use...

    {% nav entry in craft.entries.section('entry') %}                               
        
            {{ entry.getLink() }}
            {% ifchildren %}
                
                    {% children %}
                
            {% endifchildren %}
        
    {% endnav %}


Or use entry.level to target the different levels if you need to.


---

