.Param function from inside a renderhook

AH ! Thanks, problem solved. I can see why this kind of mistake is annoying and not producing any error by itself.
But since [imaging] would not match anything existing, nor - as far as I understand - are we supposed to assign new categories (I don’t remember the name) but only fill in [Params], could the system warn us in cases like this ?

You would need to code defensively.

{{ $quality := 100 }}
{{ if gt 10000000 100000 }}
  {{ with .Page.Param "imaging.quality" }}
    {{ $quality = . }}
  {{ else }}
    {{ errorf "The 'imaging.quality' parameter is not set at either the page or site level."  }}
  {{ end }}
{{ end }}

I got it, I based on wanting to changing the default [imaging] as described here Image Processing | Hugo, but that was wrong.
In fact I can’t even read those values, shouldn’t {{ warnf "%v %v" .Destination .Site.imaging.quality}} outputs something else than can't evaluate field Site in type goldmark.imageLinkContext?
I would not have had those issues if [imaging] could be changed in frontmatters without more code to add, OR if if the defaults were located in [Params] in config, and editable there, so .Params.imaging would automatically refer to the config values if not present overridden in frontmatters. Am I wrong ?

No. That message is accurate. The render hook does not receive .Site in context. You would access available site values with either the site function or the .Page.Site method.

Hugo exposes a limited set of site configuration values to the templates, and there is a Very Good Reason for that.

So, if you did either of these in the image render hook:

{{ site.Imaging.quality }}
{{ .Page.Site.Imaging.quality }}

you would get a different error message:

… at <site>: can’t evaluate field imaging …

I can’t imagine that we would ever expose the Imaging configuration to the templates, so use the site Params object instead.

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