Hello.
I’m trying to create my own breadcrumb navigation that will also show the page number in case of paginated pages. It was easy to integrate it for my section pages and I’ve got it working to some extent for my taxonomy term page also, however, it’s limited to just one taxonomy.
Here’s my code:
<!-- rest of the code -->
{{ else if eq .Kind "term" }}
<!-- parent links in the breadcumb -->
{{ range .Site.Taxonomies.tags }}
<!-- rest of the code -->
{{ end }}
{{ end }}
So, instead of declaring .Site.Taxonomies.tags
, I want to dynamically fill in the taxonomy name, depending on which taxonomy page is being rendered. For example, on a page showing posts tagged ‘A’, the breadcrumb should range though .Site.Taxonomies.tags
and if the page is showing posts categorized ‘B’, the breadcrumb should range though .Site.Taxonomies.catgories
.
I tried:
-
{{ range .Site.Taxonomies.(lower .Section) }}
, where.Section
is returningTags
andCategories
. I got the errorunexpected <.> in operand
.
{{ $taxonomy:= (printf ".Site.Taxonomies.%s" (lower .Section)) }}
{{ range $taxonomy }}
I got the error: range can't iterate over .Site.Taxonomies.tags
But, it’s working perfectly fine if I statically assign it like {{ range .Site.Taxonomies.tags }}
.
Here’s my complete breadcrumb partial: https://github.com/Hrishikesh-K/Portfolio/blob/v2/layouts/partials/breadcrumbs.html