Handle Partial-in-Partial caching / Block Inheritance

First, .Scratch.Get "singlePage" will return false even if the scratch wasn’t set, which shouldn’t happen, but the test should be more robust. For example, set a scratch named “template_type” with a value of “single” or “list”, then test for either of those values and throw an error if it’s not set. But don’t do that yet…

Second, this is an interesting read:

https://discourse.gohugo.io/t/notabug-race-condition-around-scratch-variables/17647/3

I was using $.Scratch in a partial and then passing that scratch on to a second partial. This is racy; don’t do it.

I have no idea if the second sentence is true, but it sort of matches what you describe. Additionally, the OP was using $.Scratch while you’re using .Scratch, so they may have had a scope problem instead.

Here’s what I would do as a test: eliminate the scratch, and pass the template type when calling the partial. For example:

layouts/_default/single.html:


{{ partial (print "content-type/" .Type ".html") (dict "ctx" . "template_type" "single") }}

layouts/partials/content-type/gallery.html:


{{ partial "default-content.html" (dict "ctx" .ctx "template_type" .template_type) }}

layouts/partials/default-content.html:


{{ if or (eq .template_type "single") (.ctx.Params.noSummary) }}

Unfortunately, it’s a lot more work than this, because you’ll have to prepend .ctx to every page variable referenced in the partials.

Or, you could try doing what the OP did:

Making a new scratch variable, setting “href”, “color”, and “title” on that, and then passing that scratch variable on to a second partial fixed it.