So, I have a shortcode that is called multiple times per page/ post. Inside the shortcode is a script that only needs to be rendered in HTML on the first instance of the shortcode. Does Hugo have a function for that? “Run the following HTML only once”?
Hard to find examples of .HasShortcode, so I’m trying this:
{{ if not ( .HasShortcode "ctas" ) }}
<script>
</script>
{{ end }}
But unfortunately I’m getting this error:
Building sites … ERROR 2018/10/24 10:01:01 error processing shortcode "shortcodes/ctas.html" for page "posts/test-page.md": template: shortcodes/ctas.html:1:12: executing "shortcodes/ctas.html" at <.HasShortcode>: can't evaluate field HasShortcode in type *hugolib.ShortcodeWithPage
Total in 199 ms
Error: Error building site: logged 1 error(s)
No doubt I’m using it incorrectly. Any further pointers?