Hugo

Regular page parameter inside a range

I want to use something like this in a regular page:

<ul>
    {{ range .Site.Taxonomies.series.golang }}
        <li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a></li>
    {{ end }}
</ul>

The above is copied and pasted from https://gohugo.io/templates/taxonomy-templates/#example-showing-content-in-same-series.

This works but what I really want to do is have golang be a variable that is defined in that regular page’s front matter. I’ve tried a bunch of things and they have all failed including:

{{ range .Site.Taxonomies.series.{{ .Params.t }} }}

From this failed experiment, I learned about the DOT (.) being different inside the range. So then I tried this:

{{ $t := .Params.t }}

<ul>
 {{ range .Site.Taxonomies.series.{{ $t }} }}

which also failed.

Does anyone have any tips for getting this to work?

Thanks!

Untested:

range (index .Site.Taxonomies.series $t)
1 Like

That worked, thank you very much @zwbetz! :fireworks::sparkler::tada::confetti_ball::dancer:

1 Like

Hello Again,

I’m starting to understand The DOT (.) and had a thought about the following, which I posted above and is in the Hugo docs:

<a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a>

My thought was this: I wonder if the following will work because we are inside a range and it seems like it should work:

<a href="{{ .RelPermalink }}">{{ .Title }}</a>

And it worked! My questions are:

  1. Is there any difference between these inside that range?
  2. I wonder if the docs should be updated to use the shorter simpler version?

Thanks,
N