Get section title from _index.md

mysection is a folder inside content. The folder has an _index.md with following content:

---
title: "My Awesome Section"
---

In the code below

{{ $mysection := where .Pages "Section" "mysection" }}
<h1>My Awesome Section</h1>
{{ range $mysection }}
...
{{ end }}

How do I access the section title ("My Awesome Section") from _index.md to put inside h1 instead of hard-coding it?

If the template code you posted is in a list template, e.g. layouts/mysection/list.html then you can use {{ .Title }}.

If not, you may have to use {{ (site.GetPage "mysection").Title }} or something like that.

2 Likes

The code was in index.html. {{ .Title }} did not work but the other option did. Thanks!