How to use .Params with partialCached?

I learned from the docs that:

you can use any object as cache key(s)

Great! So I did this in baseof.html:

{{- partialCached "javascript.html" . .Params.has_recaptcha -}}

That has_recaptcha front matter variable is set like so:

has_recaptcha: true

Unfortunately Hugo cannot handle this:

ERROR 2020/04/27 16:57:23 render of "page" failed:
 "C:\site\layouts\_default\baseof.html:9:12": execute of
 template failed: template: _default/single.html:9:12: executing 
"_default/single.html" at <partialCached "javascript.html" . 
.Params.has_recaptcha>: error calling partialCached: 
runtime error: invalid memory address or nil pointer dereference

How can I fix that runtime error?

Hugo Static Site Generator v0.69.2-EC9DCF30 windows/amd64 BuildDate: 2020-04-24T07:51:17Z

nil pointer dereference usually means you probably have pages without .Params.has_recaptcha set. You could try passing a default value?

{{ partialCached "cached" . ( | default false) }}
1 Like

Awesome, that works! Thanks Pointy. :slightly_smiling_face:

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