# .Param function from inside a renderhook

**URL:** <https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317>\
**Category:** support\
**Created:** [January 9, 2023, 1:26am UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317 "2023-01-09T01:26:48Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)\
**Post date:** [January 10, 2023, 1:02pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/21 "2023-01-10T13:02:35Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 10, 2023, 1:06pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/22 "2023-01-10T13:06:43Z")

</div>

You would need to code defensively.

```plaintext
{{ $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 }}

```

---

<div class="post-metadata">

**Author:** ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)\
**Post date:** [January 10, 2023, 1:24pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/23 "2023-01-10T13:24:44Z")

</div>

I got it, I based on wanting to changing the default [imaging] as described here [Image Processing | Hugo](https://gohugo.io/content-management/image-processing/#processing-options), 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 ?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 10, 2023, 7:08pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/24 "2023-01-10T19:08:40Z")

</div>

> [@Tom\_Durand](#):
>
> shouldn’t `{{ warnf "%v %v" .Destination .Site.imaging.quality}}` outputs something else than `can't evaluate field Site in type goldmark.imageLinkContext`?

No. That message is accurate. The render hook [does not receive `.Site` in context](https://gohugo.io/templates/render-hooks/#render-hooks-for-headings-links-and-images). 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:

```auto
{{ 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.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 10, 2023, 7:08pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/25 "2023-01-10T19:08:49Z")

</div>

Archived on January 10, 2023, 7:08pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [January 12, 2023, 7:09pm UTC](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317/26 "2023-01-12T19:09:24Z")

</div>

Closed on January 12, 2023, 7:09pm UTC

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

[Previous page](https://discourse.gohugo.io/t/param-function-from-inside-a-renderhook/42317.md?page=1)
