Can't access the Front Matter Params of a taxonomy page from within a Shortcode

I’m having a persistent problem accessing the basic front matter params of a taxonomy template page.

We have an /content/taxonomy-name/_index.md which renders a list of the pages within that taxonomy and the params in the front matter render correctly on it.

We then have a Shortcode that accepts pages to present a prev / next component and is used through the site

{{ $prevPage := .Get "prev_page" }}
{{ $nextPage := .Get "next_page" }}
<div class="prev-next  mt-5">
    <div class="card-deck">
        {{ if $prevPage}}{{ with $.Site.GetPage "page" $prevPage }}
        <a class="card card-transparent card-prev" href="{{ .Permalink }}">
            <p class="card-direction">Previous article</p>
            <h3>{{ .Title }}</h3>
            <p>{{ .Description }}</p>
        </a>
        {{ end }}{{ end }}

        {{ if $nextPage}}{{ with $.Site.GetPage "page" $nextPage }}
        <a class="card card-transparent card-next" href="{{ .Permalink }}">
            <p class="card-direction">Next article</p>
            <h3>{{ .Title }}</h3>
            <p>{{ .Description }}</p>
        </a>
        {{ end }}{{ end }}
    </div>
</div>

This doesn’t work at all - no data is returned from the taxonomy page front matter

{{< prev-next 
    prev_page="taxonomy-name/_index.md"
    next_page="normal-page/normal-page.md"
>}}

The closest i’ve got to it working is this - the Permalink is returned correctly, but Title is returned as ‘taxonomy-name’ and the description is not returned at all:

{{< prev-next 
    prev_page="taxonomy-name"
    next_page="normal-page/normal-page.md"
>}}

I’ve been trying to figure this problem out on and off for weeks now, and have searched extensively but never quite found anything that seemed like the same issue.

I’ve also updated to the latest version of Hugo and the problem persists.

I have the feeling I’m missing something relatively simple, or I’m failing to understand something conceptually about how taxonomies interact with the .GetPage functionality.

Any help would be greatly appreciated.

Hello there,

It is generally easier to help if you have your code in a repo somewhere easy to clone/replicate.

Unfortunately that’s not possible as this is a commercial project for a multinational corporation.

Have a read about Requesting Help to see how to make it easier to get help:

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Will do, thanks!

If you can’t share code you always can sponsor @bep, the Hugo maintainer.
There is some VIP options for you to get consulting hours from him.

This should be really really cheap and accurate for such a project and helpful for gohugo.io

1 Like