<p>Instead of using <code>{% ifchildren %}</code> use <code>{% if entry.hasDescendants %}</code>. It allows for more flexibility in your nav templating.</p>

CC BY-SA 4.0
2019-07-30T15:48:42.617Z
2019-07-30T15:48:42.617Z
Simon Kuran
<p>I want to change the URL of a li from a nav menu conditionally (using a custom field where the user sets the URL), but I don't see how to use conditionals with <code>{% ifchildren %}</code>?</p>

<pre><code>{% nav entry in entries %}
    &lt;li&gt;
        &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;

        {% if entry.id in craft.entries.descendantOf(4).ids() %}
            **change the url of all child entries**
        {% endif %}

        {% ifchildren %}
            &lt;ul class="menu sub-items"&gt;
                {% children %}
            &lt;/ul&gt;
        {% endifchildren %}
    &lt;/li&gt;
{% endnav %}
</code></pre>

<p>ID 4's children is the entry which I want to display custom URLs.</p>

<structure><navigation><children>
Change the URL of nav child entry conditionally
# Change the URL of nav child entry conditionally

(Asked by: username_0 on 2019-07-30)

I want to change the URL of a li from a nav menu conditionally (using a custom field where the user sets the URL), but I don't see how to use conditionals with {% ifchildren %}?
{% nav entry in entries %}
    
        {{ entry.title }}

        {% if entry.id in craft.entries.descendantOf(4).ids() %}
            **change the url of all child entries**
        {% endif %}

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

ID 4's children is the entry which I want to display custom URLs.

**Tags:** structure, navigation, children


---

## 1 answers

### Answer by username_1 on 2019-07-30. Score: 1 | Accepted answer

Instead of using `{% ifchildren %}` use `{% if entry.hasDescendants %}`. It allows for more flexibility in your nav templating.


---

