3

I need to split up a navigaton tree. So I try to exclude certain pages from a structure based navigation tree PLUS their children automatically, but don’t seem to get it.

{% nav page in craft.entries.section('pages').id('and,not 3,not 4,not 5') %}

Excluding certain entries like this works.

But:

{% nav page in craft.entries.section('pages').descendantOf('and,not 3,not 4,not 5') %}

… doesn’t return anything of course, because descendantOf needs one exact ID. But how could I manage to exclude entries 3, 4 and 5 AND all their children from the navigation without calling the exact IDs of all the children?

Thanks!

3

If it’s true that the descendantOf param doesn’t allow to pass in multiple entries, you probably need to work around that issue and grab the descendants for each parent entry individually.

{% set parentIds = [3, 4, 5] %}
{% set excludeIds = parentIds %}

{% for parentId in parentIds %}
    {% set ids = craft.entries.descendantOf(parentId).ids() %}
    {% set excludeIds = excludeIds|merge(ids) %}
{% endfor %}

{% set idParam = 'and, not ' ~ excludeIds|join(', not ') %}

{% set entries = craft.entries.section('pages').id(idParam) %}
  • Works like a charm, thank you!I actually don’t know for sure because of decendantOf and multiple entries. But passing multiple entries simply didn’t work so I assumed the rest. – romadev Dec 21 '16 at 10:54

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.