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 %}
        <a href="{{ entry.url }}">{{ entry.title }}</a>

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

        {% ifchildren %}
            <ul class="menu sub-items">
                {% children %}
        {% endifchildren %}
{% endnav %}

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

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.