11ty / eleventy-navigation

A plugin for creating hierarchical navigation in Eleventy projects. Supports breadcrumbs too!
https://www.11ty.dev/docs/plugins/navigation/
99 stars 16 forks source link

Current page in breadcrumb without link? #46

Open illycz opened 1 year ago

edharkins commented 7 months ago

Hi illycz,

I had a similar spec. I created a breadcrumb component and include this is my templates. I then used an Nunjucks 'If Expression' to check if it was on the last (current) page and just render the title for that.

{% set crumbs = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, { includeSelf: true }) %}

{% for crumb in crumbs %}
    {% if page.url === crumb.url %} 
        {{ crumb.title }}
    {%- else -%}
                <a class="crumb" href="{{ crumb.url | url }}">{{ crumb.title }}</a> »
    {%- endif -%}
{% endfor %}

(Due Credit: I got the base of my code from Mark Volkmann )