mhal
1
I am using the example breadcrumb partial from the documentation https://gohugo.io/content-management/sections/ with some slight modifications.
I have manually defined .Params.breadcrumb
in the frontmatter of my content for a weird edge case.
I haven’t figured out how to remove the homepage from the breadcrumbs.
How can I remove the homepage from displaying in the code below?
<nav class="flex my-4" aria-label="Breadcrumb">
<ol class="flex items-center space-x-4">
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
</ol>
</nav>
{{ define "breadcrumbnav" }}
{{ if .p1.Parent }}
{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 ) }}
<span class="text-white space-x-1">»</span>
{{ end }}
<li class="text-blue-200">
<a href="{{ .p1.Permalink }}">{{ .p1.Params.breadcrumb }}{{ if eq .p1 .p2 }}{{ .p1.Title}}{{ end }}</a>
</li>
{{ end }}
you can have a test {{ if not IsHome }}
for not adding home to breadcrumb
mhal
3
My choice of wording did not explain what I am trying to do well enough.
I want to always remove the home page from the list so that it never shows, even on nested pages
mhal
5
Okay, I tried this, per @divinerites suggestion:
<nav class="flex my-4" aria-label="Breadcrumb">
<ol class="flex items-center space-x-4">
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
</ol>
</nav>
{{ define "breadcrumbnav" }}
{{ if not .p1.IsHome }}
{{ if .p1.Parent }}
{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 ) }}
<span class="text-white space-x-1">»</span>
{{ end }}
<li class="text-blue-200">
<a href="{{ .p1.Permalink }}">{{ .p1.Params.breadcrumb }}{{ if eq .p1 .p2 }}{{ .p1.Title}}{{ end }}</a>
</li>
{{ end }}
{{ end }}
But it has an »
at the beginning.
» Depth1 » Depth2 » Depth3
How can I remove the first »
?
mhal
6
I have found a solution that works for me.
Closing the topic.
Could you please post your solution, for the future help of the Hugo community?
1 Like
system
Closed
8
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.