Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Rendering parent nodes based on key #20

Open
aaronstezycki opened this issue Nov 2, 2020 · 2 comments
Open

Conditional Rendering parent nodes based on key #20

aaronstezycki opened this issue Nov 2, 2020 · 2 comments

Comments

@aaronstezycki
Copy link

aaronstezycki commented Nov 2, 2020

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. :)

@koitaki
Copy link

koitaki commented Dec 6, 2020

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.

@aaronstezycki
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants