8/14/2017 - 9:23 AM

Pass Frontmatter to Taxonomy Without

Pass Frontmatter to Taxonomy Without

Step 1

Assign tags to your posts as you usually do like:

tags = [ "handbags", "versace" ]
Step 2

Under /content/ create a folder called brands

Within this folder create .md files for as many taxonomy terms as you need.

In your front matter include the title and description parameters you want to have rendered on your taxonomy list page, as well as a very important parameter that needs to contain the exact same tag you assigned to your posts in Step 1.

You can call this new parameter anything you want in my example I’ve called it folksy (from Folksonomy) (thanks for the link @rdwatters ) :

title = "Versace AW 2017"
description = "La Nuova Collezione di Borse Versace"
folksy = "versace"

Step 3

Now in the template for our custom brands taxonomy (that is really just a plain old Hugo Section) located at /layouts/brands/single.html place the following:

 {{ $tag:= .Params.Folksy }}
 {{ range ($.Site.GetPage "taxonomy" "tags" $tag).Pages }}
 {{ end }}  

First I assigned a variable for the folksy parameter

{{ $tag:= .Params.Folksy }}

And then I used range with a nested .GetPage function to fetch the posts I need while using the above variable to fetch the tag dynamically (sneaky ain’t it?).

{{ range ($.Site.GetPage "taxonomy" "tags" $tag).Pages }}

And that’s it!

Now you have just one taxonomy folder with the full taxonomy terms list pages and you can update them as often you need without clicking your life away.

TIP: You can also use this technique to render a taxonomy terms menu anywhere you need on your site and pass meta descriptions and other attributes to the <head> of your Hugo Project.