Related content error "can't evaluate field Related"

I have been following the related content tutorial. I have created a my-theme/layouts/partials/related.html file to generate related content. I have added the following snipped within my-theme/layouts/_default/single.html

<div id="post-content">
                      {{ .Content }}
                      {{ partial "related.html" . }}
                    </div>

I have added the following to config.toml

[[related.indices]]
name = "keywords"
weight = 0
[[related.indices]]
name  = "author"
toLower = true
weight = 30
[[related.indices]]
name  = "tags"
weight = 100
[[related.indices]]
name  = "date"
weight = 10
pattern = "2006"

I receive the following error from Hugo:

ERROR 2018/01/22 20:43:55 Error while rendering "page": template: theme/_default/single.html:34:44: executing "theme/_default/single.html" at <.Site.RegularPages.R...>: can't evaluate field Related in type hugolib.Pages

I am using Hugo v 0.31.1.

You need to call .Related on a Page (not a list). I’m being short here, because I cannot pin-point exactly without seeing the source.

Thanks for your reply. I thought I was calling it in that way, but I’m new to Hugo. Let me add more code.

my-theme/layouts/partials/related.html contains this:

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

my-theme/layouts/_default/single.html contains this:

                <div id="post-content">
                  {{ .Content }}
                </div>

                {{ partial "related.html" .}}

config.toml contains this:

# related content
[related]
# Only include matches with rank >= threshold. This is a normalized rank between 0 and 100.
threshold = 80
# To get stable "See also" sections we, by default, exclude newer related pages.
includeNewer = false
# Will lower case keywords in both queries and in the indexes.
toLower = false

[[related.indices]]
name = "keywords"
weight = 0
[[related.indices]]
name  = "author"
toLower = true
weight = 30
[[related.indices]]
name  = "tags"
weight = 100
[[related.indices]]
name  = "date"
weight = 10
pattern = "2006"

If there is more source that would be helpful, I am happy to provide it. It’s really great that Hugo has added related content.

Sorry, I cannot spot the error from what you have posted. Please not post more snippets. If you can post a link to the source (GitHub?), someone might have a look at it.

Here is the source of an example site on GitHub which replicates the error when npm start is called.

Sorry to bump this thread, but I’m revisiting this now as it is one of my last issues and still hoping someone can help. There is probably something quite basic here but I am stuck. When I try to iterate over .Site.RegularPages I can generate a list at the bottom of the page. However, as soon as I try to call .Site.RegularPages.Related, I get the message “…can’t evaluate field Related in type hugolib.Pages.”

I have copied the code from the Hugo repo for my related.html partial. Failing site can be found here.

I cannot get npm start to run and don’t have time to debug it. This “Victor Hugo” is pretty complex, so, you might have better luck asking the person who authored it in the first place?

In the theme you copied related.html from, it’s getting called from single.html.

There’s no single that I can find in your repo (I assume that means it’s being generated or downloaded by the install process, somehow), so, please paste your whole single here?

1 Like

Your suggestions about Victor Hugo being the problem was a good one. I tried with hugulp and it works flawlessly. I will open an issue on the Victor Hugo repo.

1 Like