Reference another page via front matter

I’m fairly new to HUGO, so I may not be asking the right question. I am open to any suggestion on how to accomplish my task. Thanks in advance!

Here is the scenario: I’m building a website for a band. There are two content sections at play: blog and discography. In the discography section there will be a list of all of the band’s music with audio players to listen, the album art, etc. In the blog section, there will be blog posts on various topics, and for each album, there will be a blog post about that album.

In the discography section, I would like to have a preview of the blog post associated with each album and a link to the blog post to continue reading. I thought I would be able to do this by putting a reference to the related blog post in the front matter of the album and then referencing that page in the layout of the album. However, I can’t find a way to do that.

What I’ve tried:

  1. A front matter entry like this:
blogPost: /blog/

and then in my layout:

{{ with .Params.blogPost }}
    {{ .Content }}
{{ end }}

But it seems that blogPost is simply interpreted as a string (which makes sense.)

  1. Using {{< ref "blog/" >}}
    This doesn’t seem to help, it creates the correct link, but doesn’t let me reference the page object and thereby access its .Content.

  2. The docs have this section titled “Target specific pages” but it seems to be only related to targeting them for inheritance of front matter.

Here is the repo for context:

  1. Perhaps your repo is private.

Sorry about that. Should be public now.


{{ define "main" }}
  {{ range .Pages }}
    <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
      {{ with .Params.blogPost }}
        {{ with site.GetPage (printf "blog/%s" .) }}
          Related blog post: <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
        {{ end }}
      {{ end }}
  {{ end }}
{{ end }}

And in your album front matter:

blogPost: "blog-1"

Your blog pages currently have draft: true. Make sure you’re testing with hugo server -D.

Thank you so much! That does the trick just right.

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