I’ve got a shortcode that loads Javascript in a footer.html partial, inside a .HasShortcode check. This works fine with ordinary pages.
I’m creating a one-page theme that builds index.html by ranging through content from a headless bundle. Some of the pages in that bundle, but not the content of index.html itself, call the shortcode in question.
In this instance .HasShortcode doesn’t return the expected JS block. I guess that’s because the page itself doesn’t have the shortcode, but rather the page that is looped over?
Is there a way around this, or something I’m missing?
I don’t have a public repo available but here is the relevant setup:
footer.html
{{ if .HasShortcode "shortcode" }}
{{ block "shortcode-js" . }}{{ end }}
{{ end }}
shortcode.html
{{ define "shortcode-js" }}
<!-- code -->
{{ end }}
<!-- rest of the shortcode -->
index.html
{{ $sections := site.GetPage "home_sections" }}
{{ range sort $sections.Pages "File.Path" }}
<!-- stuff -->
{{ end }}
Content directory
.
├── home_sections
│ ├── _index.md
│ ├── section1.md
│ ├── section2.md
│ └── section3.md
└── _index.md
_index.md in home_sections
---
title: "Home Sections"
_build:
list: 'local'
publishResources: false
render: 'never'
---
The shortcode is in section1.md
Thanks!