11ty/eleventy-navigation

Conditional Rendering parent nodes based on key

aaronstezycki opened this issue · 2 comments

Hi, I'm just wondering if you can conditionally render container nodes by querying if a current page has a key or parent?
Most of the navigation examples, contain ul around the loop, however if there are no posts to bring back, we're left with an empty ul. Is there any way we can circumvent that?

i.e:

{% set navPages = collections.all | eleventyNavigation('specific-key') %}
{% if post.key %} or {% if post.parent %}
<ul>
{%- for entry in navPages %}
    <li{% if entry.url == page.url %} class="my-active-class"{% endif %}>
        <a href="{{ entry.url | url }}">{{ entry.title }}</a>
    </li>
{%- endfor %}
</ul>
{% endif %}

Apologies if the answer is obvious, I'm a little bit of a noob with nunjucks. :)

I'm wondering this too, though for a slightly different reason.
I've currently got an error saying "Node does not exist", hence I'm looking to avoid that via a conditional nunjucks expression.

I suppose it's a case of knowing what data is available to query for such a thing, but also knowing the data cascade and if that data is available at template or post level.