Stream of Consciousness

Mark Eschbach's random writings on various topics.

Hugo post categories and tags

Categories: tech

Tags: hugo styling

Rendering file for posts is located at tehems/{theme}/layouts/posts/single.html by default.

Parameters are accessible as .Params.categories for the given page as a string. Documentation does render the following fragment correctly, however it properly capitalizes the title. How proper.

{{ $taxonomy := "tags" }}
{{ with .GetTerms $taxonomy }}
  <p>{{ (site.GetPage $taxonomy).LinkTitle }}:</p>
  <ul>
    {{ range . }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}

To maintain the casing for either categories or tags then use the attribute .Name instead of .LinkTitle.

Debugging

  • To print a value as JSON use {{ . | jsonify }} . Documentation.
  • For hugo code fragments the best I have found is go-html-template . Supported list