Hugo 101: how to select a page based on a tag

I am just beginning with Hugo and Go. I want to do a pretty simple thing and can’t figure it out. In a list page – I want to style pages with “link” tag differently. How to select the pages that have a specific tag. I tried to do it this way:

{{range .Pages}}
{{ $tag := .Params.Tags }}
{{ if eq $tag "link" }}
  <p>Print something else</p>
  <hr>
{{else}}
  <h3><a href="{{.URL}}">{{.Title}}</a></h3>
  {{.Content}}
  <p>{{.Params.tags}}</p>
  <p>{{.Params.types}}</p>
  <hr>
{{end}}
{{end}}

Variables are super confusing. I don’t understand what the dot {{.}} is doing. Why sometimes you should capitalize the first letter why sometimes you shouldn’t. I went through Giraffe Academy tutorials and read some documentation. Is there a good place for me to learn this give that I am new to the frontend world?

For your first question:

.Params.tags will return a slice of strings (array), it’s a list of tags associated with the page.

So you could use the in function, (if in .Params.tags "link")

For your second question, this post should give you more context on the dot etc…: https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/

1 Like