Using Parameters in Your Theme

In Hugo, you can access the parameters specified in the front matter of your content files (e.g., Markdown files) through your Hugo templates. These are called ‘Page-level Params’. This post explores how you can use these within your theme.

We’ll be using an example of featured_image added our post below.

1
2
3
4
5
---
title: "My Post"
date: 2023-06-01
featured_image: "/img/2022/goldie1.jpg"
---

You can then use this parameter when editing your theme using the template tag shown below:

1
{{ .Params.featured_image }}

Which will be swapped to:

1
/img/2022/goldie1.jpg

So, likewise, we can also add it inside an img element to display:

1
<img src="{{ .Params.featured_image }}" alt="">

And that’s all there is to it, g’luck!