Detecting the use of shortcodes

layouts/shortcodes/my-shortcode.html

{{ .Page.Store.Set "email" "john@example.org" }}

layouts/_default/baseof.html

{{ .Store.Get "email" }}

If I understand the rendering order correctly, shortcodes are lazy loaded, so I believe there is no guarantee that the .Store value will be available at the top of your baseof template until .Content has been rendered.

To make sure that it is available, force .Content rendering before retrieving the .Store value. You can use any of the following to force .Content rendering:

  • Content
  • FuzzyWordCount
  • Len
  • Plain
  • PlainWords
  • ReadingTime
  • Summary (regardless of how you define it)
  • Truncated
  • WordCount

Example baseof.html

<head>
  ...
  {{ $noop := .WordCount }}
  {{ .Store.Get "email" }}
</head>
6 Likes