Option that does not include the name of the current page in the breadcrumbs. Also this code allows to make custom headers for the elements of the chain.
{{ $baseurl := .Site.BaseURL }}
{{ $fullurl := print ( .RelPermalink | replaceRE "[^/]+/$" "") }}
<ol class="breadcrumbs">
<li><a href="/" class="crumb">⌂</a></li>
{{ range $index, $element := split $fullurl "/" }}
{{ $.Scratch.Add "path" $element }}
{{ if ne $element "" }}
<li><a href='{{ $baseurl }}{{ $.Scratch.Get "path" }}'>{{ if isset $.Site.Data.titles . }} {{ index $.Site.Data.titles . }} {{ else }} {{ . }} {{ end }}</a></li>
{{ $.Scratch.Add "path" "/" }}
{{ end }}
{{ end }}
</ol>
Custom headers should be written to the file \data\titles.yaml. They should look like this:
lib: "Библиотека"
book: "Книга"
book1: "Книга 1"
If you have the folders structure lib/book/article/, it will look like: Библиотека > Книга.
It would be great if this could be added to the Hugo docs. It’s such a common navigational element that it would help a lot of people. I think it would belong well alongside Menu Templates, Pagination and so on.
In short, the URL is the raw URL definition of the page, and should probably unexported, but that would probably break more than it would help. But my point is that URL may in many cases differ from RelPermalink, which will be bad if you use it in a theme.
Links of this implementation way up the chain is all messed up for me.
URL like http://localhost:1313/videos/season-1/ outputs a list of three items with links as http://localhost:1313/, http://localhost:1313/videos/season-1//http://localhost:1313/videos and http://localhost:1313/videos/season-1//http://localhost:1313/videos/season-1 respectively.
Currently trying to make this code work with this one, that’s way more elegant and have working URLs but duplicates content.
I can’t say for sure that this will solve your problem because I changed the way I do mine when I started using Custom URLs with which, obviously, this code doesn’t work since there are little to none URL components to be analyzed.
As much as I can tell from this old commit I’ve found (lucky you :p), what I did to solve the problem back then was to initialize a Template Variable with the scope of the “dot” that’s passed to the Partial Template and instead of calling the Scratch from the context of the dollar-sign (or whatever it’s called in Hugo/Go) I used this variable I initialized.
YES! Finally got it to work thanks to your code changes, this is what I have ended up with incase someone needs it. Since I am new to HUGO not sure if the below code could be improved but it works for now. Thank you @magnusthorek
@magnusthorek sorry, just realised that the pagination is not outputted as position 3, so if I have: Home - Blog - Page 3 I only see Home - Blog even if I am on `page 3, my taxonomies work just perfectly.
This approach (@maltesa/@alexandros 's) is not working for me for taxonomyterm lists. I would expect the breadcrumb nav on https://site.com/categories/foo to be home > categories > foo, but instead it shows only home > foo.
so that it instead displays the title of the page? If I change . to .Title I get the following error message:
error calling partial: template: partials/breadcrumb.html:9:79: executing "partials/breadcrumb.html" at <.Title>: can't evaluate field Title in type string
Using title . or a similar function won’t work well for my needs. Thanks.