Adding a new segment in breadcrumb navigation?

Hello everyone,

I want to add a breadcrumb navigation to my site and using this one 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 :frowning:

<ol  class="nav navbar-nav">
  {{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
{{ 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>
{{ 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 }}
<!-- 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.

Thanks again and appreciate the help!

Taxonomies in Hugo have no hierarchy, instead they exist side by side and independent of sections.

So a breadcrumb nav in Hugo makes sense only for Sections, Nested Sections and their content children.

If anyone ever comes up with a mixed breadcrumb (i.e. for both sections and taxonomies) then that would be a very interesting thing to see.