Open sascha53 opened 7 years ago
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master
branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
This is a breaking change for setups that use Scratch to communicate between templates.
For communication between output-formats, it is necessary for Scratch to persist between output formats. There is no good fix for this if the current behavior is changed. In contrast, the OP's use case can be addressed with the current system with this code.
In the head of each template:
{{ .Scratch.Set "RenderedIcons" (slice ) }}
And then for each icon:
{{- $icon_id := "line-chart" -}}
{{ if in (.Scratch.Get "RenderedIcons" ) $icon_id }}
// output svg
{{ .Scratch.Add "RenderedIcons" (slice $icon_id) }}
{{ else }}
// output ref to svg
{{ end }}
It is easy to flush portions of the cache manually, but hard to communicate persistently across live-reloads and templates, etc. Making Scratch more ephemeral is a breaking change, though making it more persistent (especially persistence between runs) increases its utility.
For this reason, I do not think this change should be made.
I use partials for inlining svg defs, for example:
The goal is to inline a svg defs just once per page, as i reference them with xlink:href. This is what the if statement is made for and that worked well before activating another output format like AMP, which is also using this icon partial in its template.
It seems that the vars defined in Scratch are "reseted" per page, but if you use multiple Output Formats, they are shared and not reseted. The undesired behaviour in my case: Either on the HTML or AMP version of the same page, which is rendered after the other (which is random) the var is already set to true and the svg def isn't rendered.
This also doesn't work:
The solution would be either a proper reset of the Scratch vars for every Output Format. Or a page variable that tells me which output format is currently rendered (or extension) and that i can use in an if statement. Or maybe something else.