I’m using Hugo 0.134.0, Go 1.23.1 and Hugo Cache Resources. My build command is hugo --noChmod --gc --minify.
In Netlify, when I repeat build several times, something weird happens.
Often .Scratch.Get "large" works but sometimes not, it doesn’t take true in the item partial.
If I clear cache and rebuild in Netlify, it displays correctly.
Example code:
items.html
{{ range $pages }}
{{ .Scratch.Set "large" true }}
<div class="{{ if .Scratch.Get "large" }}is-large{{ end }}>
{{ partial "item" . }}
</div>
{{ end }}
item.html
<div class="{{ if .Scratch.Get "large" }}is-large{{ end }}>
{{ .Title }}
</div>
{{ .Scratch.Delete "large" }}
I need to keep the context in {{ . }}
Could you please help me?
I don’t know if I’m using .Scratch wrong or not.
The Scratch and Store methods are quite reliable. I always use the latter because it survives rebuilds when running hugo server.
As @irkode describes, the most common mistake made by site and theme authors is that they ignore concurrency, attempting to “get” a scratch pad value before it has been set. This condition, and the proper way to handle it, is described here: