How to List Sections before Page Title

I recently added a short recursive partial based loosely on the section on breadcrumb navigation listed in the content sections doc page to my website and thought I would list it here in case anybody found it useful.

To start with, my content folder looks like this. Because my index (home) page is a disclaimer before entering the site, I don’t want to use the methodology used in the documentation linked above to list its title:

├── _index.html
├── section
│   ├── _index.html
│   └── ...
└─ ...
    ├─ _index.html
    └── ...

Therefore, the root _index.html has the following in the metadata:


A little heavy-handed, but if you use a standard home page you could replace the test for .p1.Params.isroot listed later below with a test for .p1.IsHome.

Now, onto the meat of the technique:

In: ./themes//layouts/_default/baseof.html , or, ./layouts/_default/baseof.html:

    {{ block "title" . }}
        {{ partial "cat_recursive.html" (dict "p1" . "p2" . "title" .Site.Title) }}
    {{ end }}

And, in ./themes//layouts/partials/cat_recursive.html , or, ./layouts/partials/cat_recursive.html:

{{ if .p1.Parent }}
    {{ partial "cat_recursive.html" (dict "p1" .p1.Parent "p2" .p2 "title" .title ) }}
{{ else }}
    {{ .title }} / 
{{ end }}
{{ if eq .p1 .p2 }}
    {{ .p1.Title }}
<!-- Replace test condition below with .p1.Ishome for standard home pages. -->
{{ else if not .p1.Params.isroot }}
    {{ .p1.Title }} / 
{{ end }}

Resulting in a title like: Site Title / Section Title / Subsection Title / Page Title

Not exactly for everybody (some people prefer a simpler Site Title / Page Title, or different for blogs, etc.), but I figured I would post this up just in case.

Have a good day and keep on hacking.

EDIT: fixed tree thingo.