Search code examples
yamlmarkdownmetadatahugotoml

Hugo markdown metadata


I want to show metadata from the markdown file on the webpage so I'm trying to access it using the variable names (e.g. {{ .Author}} ).

This works fine with the .Title and .Content variables, but does not work with the others! It seems like I'm missing an important detail on how to use these. With the .Author variable the output on the page is { map[]}.

Thanks in advance

Markdown file:

---
title: ABC
author: "Foo Bar"
position: Manager
---


The actual content ...

Webpage:

{{ range where .Data.Pages "Type" "type"}}
<section>
    <div>
        <div>
            {{ .Title }}<br>
            {{ .Content }}
        </div>
        <div>
            {{ .Author }}<br>
            {{ .Position }}
        </div>
    </div>
</section>
{{ end }}

Solution

  • Turns out you need to access the non-standard parameters via the .Params variable.

    See https://gohugo.io/variables/page/ for the relevant information.

    {{ range where .Data.Pages "Type" "type"}}
    <section>
    <div>
        <div>
            {{ .Title }}<br>
            {{ .Content }}
        </div>
        <div>
            {{ .Params.author }}<br>
            {{ .Params.position }}
        </div>
    </div>
    </section>
    {{ end }}