1

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 %}
    <li>
        <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 %}
            </ul>
        {% endifchildren %}
    </li>
{% endnav %}

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

1

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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