Harry Cresswell

Specific Page Content on your Hugo homepage

This is a pretty simple Hugo snippet for displaying content from a specific page on your site homepage.

Say for example I wanted to add the title and content from a page called “How it works” on my homepage.

First I’d need to create a page called how it works.

$ hugo new page/how-it-works.md

In the page front matter add a parameter called type and give it a value which makes sense.

That might look something like this:

title: "How It Works"
date: 2018-03-02T14:58:10+01:00
type: "how"

Then in your index.html add the following:

<!-- show contents of how it works page -->
  {{ range .Data.Pages }}
      {{if eq .Type "how" }} <!-- look for type in the front matter of page -->
        <h2 class="f3">{{ .Title }}</h2>
        <p>{{ .Content }}</p>
  {{ end }}

That’s it!

Join my mailing list

My Brain—tactics contains a bunch of useful tools, articles and tips. No spam ever, just good honest content. Unsubscribe with one click.