Closed jmooring closed 9 months ago
I'm not sure. When passing state around with scratch you're already in advanced territory and need to understand how things fits together.
{{/* Prepare content. */}}
{{ $content := .Content }}
{{/* Check if mermaid was used during the content rendering above. */}}
{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
{{/* Print content. */}}
{{ $content }}
The above could even be rewritten to:
{{ with .Content }}
{{/* Check if mermaid was used during the content rendering above. */}}
{{ if $.Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
{{/* Print content. */}}
{{ .}}
{{ end }}
Yeah, this just need to be documented. See https://github.com/gohugoio/hugoDocs/issues/2402.
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.
Something like this within the
head
element of a template will not work because.Content
has not been evaluated:So we do something like this instead:
Instead of
Content
you can also invokeFuzzyWordCount
,Len
,Plain
,PlainWords
,ReadingTime
,Summary, Truncated
, orWordCount
.Although
{{ $noop := .OneOfTheAbove }}
makes sense to me, it is not intuitive to new or casual users.I don't have any great suggestions at the moment, so maybe what we have is fine.