I’ve developed custom footnote shortcodes which add CSS styling based on the reference elements’ ID attributes. In other words, it’s not possible to “foresee” the IDs and to write the CSS statically (in advance); it must be done dynamically inside the shortcodes.
While the styling produces the design I intended, I noticed that the <style>
element is not actually permitted in the <body>
when viewing the generated HTML source code in Firefox, but is only allowed in the <head>
. Didn’t know that!
In order to keep my HTML valid, I looked for
- HTML workarounds like slapping the
scope
attribute onto the<style>
element but that’s deprecated, - Hugo workarounds to move the
<style>
element to the<head>
somehow but couldn’t find anything.
Naturally, a template at the top of the page (like my head.html
partial) will be executed earlier than a template at the bottom (like my footnotelist.html
shortcode), so the head partial won’t be able to read .Page.Store
variables set by the footnote shortcode.
ChatGPT recommended me to do this:
{{ $content := .Content }}
<!DOCTYPE html>
<html>
<head>
{{ partial "head.html" . }}
</head>
<body>
{{ $content }}
</body>
</html>
Is that good practice? Or should I just accept the syntax error? Or do something else entirely?