<p>In that case you can put this in the <code>href</code> value:</p>

<pre><code>{{ entry.descendants.type('page').first.url ?? '' }}
</code></pre>

<p>(Replace <code>page</code> with the other entry type handle(s).)</p>

CC BY-SA 3.0
2017-03-27T14:28:13.027Z
2017-03-27T14:28:13.027Z
Brandon Kelly
<p>I have a navigation structure as follows:</p>

<pre><code>{% set page = entry ?? category ?? null %}

&lt;ul class="nav menu--main"&gt;
    {% nav entry in entries %}

        &lt;li class="menu__item{% if page and page.id == entry.id %} is-current{% endif %}"&gt;

            &lt;a {% if entry.type == 'noLink' %}href=""{% else %}href="{{ entry.url }}"{% endif %}&gt;{{ entry.title }}&lt;/a&gt;

            {% ifchildren %}
                &lt;ul class="nav menu--submenu__wrapper"&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}

        &lt;/li&gt;

    {% endnav %}
&lt;/ul&gt;
</code></pre>

<p>As you can see, I have an <code>entry.type</code> called "No link" which means that the user doesn't want the parent page to have a page of it's own, yet it still needs to appear in the nav to give context to the children.</p>

<p>My question is; how can I get the first child's URL within the <code>ifchildren</code> tags so I can make the parent automatically redirect to the first child's page in the navigation?</p>

<p>I know how to do this in regular forloops, but it would be nice to do this within Craft's <code>nav</code> tags.</p>

<p>Thanks,
Jay</p>

<navigation><forloop><loop><children>
How to get first child URL within Craft/Twig Nav tags
# How to get first child URL within Craft/Twig Nav tags

(Asked by: username_0 on 2017-03-27)

I have a navigation structure as follows:
{% set page = entry ?? category ?? null %}


    {% nav entry in entries %}

        

            {{ entry.title }}

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

        

    {% endnav %}


As you can see, I have an entry.type called "No link" which means that the user doesn't want the parent page to have a page of it's own, yet it still needs to appear in the nav to give context to the children.
My question is; how can I get the first child's URL within the ifchildren tags so I can make the parent automatically redirect to the first child's page in the navigation?
I know how to do this in regular forloops, but it would be nice to do this within Craft's nav tags.
Thanks,
username_0

**Tags:** navigation, forloop, loop, children


---

## 1 answers

### Answer by username_1 on 2017-03-27. Score: 2 | Accepted answer

In that case you can put this in the href value:
{{ entry.descendants.type('page').first.url ?? '' }}

(Replace page with the other entry type handle(s).)


---

