HUGO

Using .RegularPages.Related gives me "keywords" index support error

Hi! I’m trying to create a Related Content section in a page using .Site.RegularPages.Related as shown in the docs, but it gives me the following error, saying something about “keywords” index not being supported (?)

Start building sites … 
ERROR 2021/11/19 17:09:24 render of "page" failed: "....../themes/basic/layouts/posts/single.html:32:32": execute of template failed: template: posts/single.html:32:32: executing "main" at <.Site.RegularPages.Related>: error calling Related: indexing currently not supported for index "keywords" and type []interface {}
Built in 158 ms
Error: Error building site: failed to render pages: render of "page" failed: "....../themes/basic/layouts/posts/single.html:32:32": execute of template failed: template: posts/single.html:32:32: executing "main" at <.Site.RegularPages.Related>: error calling Related: indexing currently not supported for index "keywords" and type []interface {}

I’m following the indication in the docs, like this:

<section class="related">
    {{ $related := .Site.RegularPages.Related . | first 5 }}
    {{ with $related }}
        <h3>Related pages</h3>
            <ul>
                {{ range . }}
                    <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
                {{ end }}
            </ul>
    {{ end }}
</section>

And adding the “keywords” param in the front matter, like this:

keywords:
- keywordA
- keywordB

If it’s any useful to know I’m following the book “Build websites with HUGO”, by Brian P. Hogan

I already tried specifying the related content config in the config.toml file or even using a more “manual” approach, like this:

{{ $related := .Site.RegularPages.RelatedIndices . "keywords" | first 5 }}

… but it didn’t worked either.

Any ideas? I’ll gladly share any other relevant information about this. Thanks in advance!

Project repo: GitHub - dredstrauss/dev-portfolio-hugo: Learning project using HUGO framework

I’m unable to reproduce the problem. Can you share your project with us?

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

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.

Oh! Sure thing! Thanks for the indication :grin:

Your site builds without errors.

I’m sorry, I commited my last version without this part. My bad. Now I commited the failed version.

Your site builds without errors if you comment or remove this line from your site configuration:

keywords = ["fullstack","javascript","bootstrap","backend","frontend","developer"]

I don’t understand why there’s a conflict, but I haven’t given it much thought either.

1 Like

I see. Thanks for adding that Issue!
I’ll keep checking how it goes.

Best regards.