gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.77k stars 7.53k forks source link

Cannot use .Scratch method in .Render #12089

Closed Lruihao closed 8 months ago

Lruihao commented 8 months ago

At single.html, the .Scratch method is valid:

{{- $author := .Scratch.Get "author" -}}

But via .Render, the .Scratch method is invalid:

{{- range $pages.Pages -}}
  {{- .Render "summary" -}}
{{- end -}}

In summary.html, .Scratch.Get "author" got <nil>

I don't know why, but what I can confirm is that this bug occurs after updating version 0.123.0.

Complete code

What version of Hugo are you using (hugo version)?

This problem occurs in 0.123.0

$ hugo version
hugo v0.123.0-3c8a4713908e48e6523f058ca126710397aa4ed5+extended darwin/arm64 BuildDate=2024-02-19T16:32:38Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

bep commented 8 months ago

.Scratch works fine in .Render.

Lruihao commented 8 months ago

Oh sorry, it's not work fine for my theme:

At summary part, it's bad..

image

But, at single page,it's work fine like before:

image

see post-author.html

It was working fine up to version 0.122.0, but after updating to 0.123.0 it became terrible. Looking forward to your solution.

jmooring commented 8 months ago

@Lruihao I am unable to reproduce the problem. I followed your instructions: https://fixit.lruihao.cn/documentation/getting-started/

Instead of asking us to create a new site, configure it, and create content, please create a minimal reproducible example that consistently fails.

Lruihao commented 8 months ago

@jmooring There is a demo & repo that can reproduce the problem.

jmooring commented 8 months ago

@Lruihao Please provide step-by-step instructions, including which page I am supposed to view to see the problem.

jmooring commented 8 months ago

OK, I can intermittently reproduce the problem looking at the home page... with version v0.122.0.

This has nothing to do with v0.123.0.

It's happening intermittently when you run hugo server because scratch pads set with .Scratch.Set do not survive server rebuilds. Use .Store.Set and .Store.Get instead. See: https://gohugo.io/methods/page/store/

And make sure you read the section titled "Determinate values": https://gohugo.io/methods/page/store/#determinate-values

If you need additional assistance please create a new topic in the forum. Thanks.

Lruihao commented 8 months ago

@jmooring In fact, I tried before creating this issue Store, but this issue still occurs during the first Hugo serve or build, so I reverse this commit.

I will create a discussion on the forum later. Thanks!

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.