This looks at the raw content of the page. If it finds that you’ve called a shortcode via {{< foo >}} or {{% foo %}} it will add add some CSS and JavaScript.
EDIT: This is a generic, low-level approach to parsing content. I’ve used this in the past to search for the inclusion of AMP components, specific HTML attributes, etc. To look for an individual shortcode, use .HasShortcode instead.
I find this quite awkward (and prone to future portability issues) … is this the best we have? It sounds like block/define should have been the answer but their behavior still stumps me – you can have multiple defines of something and don’t get duplicate content in all pages, while other defines do push their guts in all pages. Docs aren’t very clear.
Given that the page content is fully processed before it is passed to the base html I’d expect to be able to exchange information via the page Scratch.
But would .Page.Scratch be populated when baseof.html is supposed to output ? In other words, does Hugo populate all .Content and .Page.Scratch before starting to render html in baseof.html? I didn’t find a clear explanation of the order of execution of the various components in Hugo. Looking again at @jmooring’s example above, he suggests doing a regex find on .Content to detect if some html string exists that was part of a shortcode, but shortcodes can be called in a number of places, e.g. invoked from some partial called within inside baseof.html, and all sort of other funky invocations. Are there clear docs to explain the execution path to cover all situations?