I want to add a breadcrumb navigation to my site and using this one https://gohugo.io/content-management/sections/#example-breadcrumb-navigation which works very well. My only question is now can I add another segment? Reason being I have some pages that are nested 3 levels. I tried to add .p3 to the code but it broke
<ol class="nav navbar-nav">
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
</ol>
{{ define "breadcrumbnav" }}
{{ if .p1.Parent }}
{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 ) }}
{{ else if not .p1.IsHome }}
{{ template "breadcrumbnav" (dict "p1" .p1.Site.Home "p2" .p2 ) }}
{{ end }}
<li{{ if eq .p1 .p2 }} class="active"{{ end }}>
<a href="{{ .p1.Permalink }}">{{ .p1.Title }}</a>
</li>
{{ end }}
I broke my repo as well lol but hope to get it back.
Thanks in advance,
Emma x
This is what I use to go 3 levels deep. i.e. Home > First Section > Nested Section > Content file (within Nested Section). It’s sort of based on this old post albeit adapted to current day Hugo.
<span class="breadcrumb">
<a href="/">Home</a><span> > </span>
{{ template "breadcrumb" dict "currentPage" .Page "perma" .Permalink }}
</span>
<!-- templates -->
{{ define "breadcrumb" }}
{{ if .currentPage.Parent }}
{{ if ne .currentPage.Parent .IsHome }}
{{ template "breadcrumb" dict "currentPage" .currentPage.Parent }}
{{ end }}
{{ if eq .perma .currentPage.Permalink }}
<a href="{{ .currentPage.Permalink }}">{{ .currentPage.Title }}</a>
{{ else }}
<a href="{{ .currentPage.Permalink }}">{{ .currentPage.Title }}</a> >
{{ end }}
{{ end }}
{{ end }}
Note that the above breadcrumb will not work for taxonomies.
Oh thank you @alexandros your code worked better for what I needed, but shame about it not working for taxonomies (( breadcrumbs seem to be a very frustrating thing when you mix taxonomies and nested pages.