I’d like to have a shortcode for hero content which allows the post author to place the content within the body of the markdown, but allow me to place the inner content in a different location (in this specific case, the <heading> tag for the article.
I attempted doing this via the following method, but it did not work. Is this achievable by some other means?
{{ $noop := .WordCount }} <-- force .Content to be rendered first
{{ with .Store.Get "hero_content" }}
<header>
{{ . | $.RenderString }}
</header>
{{ end }}
In contrast to the .Scratch method, this Scratch is not reset on server rebuilds.
The .Store value is initialized when the content is rendered, but we need the value before the content is rendered. Instead of trying to remember the rendering sequence and the nuances of concurrency, I always force content to be rendered to a “no-op” variable if I need a .Scratch or .Store value before calling .Content in a template.
See this post for a list of methods that cause content rendering.
I’m not sure I’ve seen a problem when building a site, but I’ve definitely seen a problem when editing templates while running hugo server.
You can obviously create a footnote that appears immediately below the .Inner content, but I can’t think of a way to place that footnote at the bottom of the page; you’re rendering the shortcode content outside of page rendering.
git clone --single-branch -b hugo-forum-topic-46317 https://github.com/jmooring/hugo-testing hugo-forum-topic-46317
cd hugo-forum-topic-46317
hugo server