Content sections frontmatter

Hello! I’ve been using Hugo for years, but some things still seem to elude me. Let’s say I’m trying to add a little pizzazz to my archive pages by adding an icon next to the section’s title. Here’s my section’s _index.md:

---
title: "A clever title"
description: "A nice description."
icon: "😆"
---

This section.html has always worked:

{{ define "main" }}
<header>
	<h1>{{ .Title }}</h1>
	{{ with .Description }}<p>{{ . }}</p>{{ end }}
</header>

<div class="content">
	{{ range .Pages }}
		<!-- More logic. -->
	{{ end }}
</div>
{{ end }}

As soon as I do this, all hell breaks loose:

{{ define "main" }}
<header>
	{{ with .Icon }}<p>{{ . }}</p>{{ end }}
	<h1>{{ .Title }}</h1>
	{{ with .Description }}<p>{{ . }}</p>{{ end }}
</header>

<div class="content">
	{{ range .Pages }}
		<!-- More logic. -->
	{{ end }}
</div>
{{ end }}

Can someone explain what I’m missing?

“description” is a predefined page variable. See:
https://gohugo.io/variables/page/#page-variables

“icon” is not a predefined variable. See:
https://gohugo.io/variables/page/#page-level-params

Access the value of the “icon” front matter field with:

{{ .Params.icon }}

Eff me, I don’t know why I blanked on the .Params part. Thanks!

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.