Can't evaluate field in type (partials)

Pretty simple error when trying to check if a variable exists:

{{ partial "books.html" .  }}

Then in books.html:

{{ if .column }}
{{ end }}

Error:

error calling partial: template: theme/partials/books.html:3:6: executing "theme/partials/books.html" at <.column>: can't evaluate field column in type *hugolib.PageOutput

Error disappears if I remove the dot from the partial.

{{ partial "books.html"  }}

But even when it serves my purposes, I’m not sure if that’s how partials should be called (without the dot)

Help is appreciated

This article is helpful:

2 Likes

What is .column where are you declaring it? Is it front matter? If so .Params is needed to access it how about you try this in your partial {{ printf "%#v" . }} and this will output all the context available in your partial.

One of the most common mistakes with new Hugo users is failing to pass a context to the partial call. In the pattern above, note how “the dot” (.) is required as the second argument to give the partial context. You can read more about “the dot” in the Hugo templating introduction.

1 Like