Using Parameters in Your Theme

☕  Ad-blocker? Consider buying me a coffee instead :)

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
Copy to Clipboard
---
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
Copy to Clipboard
{{ .Params.featured_image }}

Which will be swapped to:

1
Copy to Clipboard
/img/2022/goldie1.jpg

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

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

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