I have a shortcode “putsubmenu” that I want to use to put a specific menu:
<div class="buttons">
<a class="button" href="/maintopic"><span class="icon"><i class="fas fa-anchor"></i></span></a>
{{ $currentPage := (.Get 0) }}
{{ range $.Site.Menus.mainsub }}
<a class="button{{ if $currentPage.IsMenuCurrent "mainsub" . }} is-active{{ end }}" href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
</div>
Then in markdown files, I specify they are a member of the “mainsub” menu in frontmatter:
menu:
mainsub:
Name: Some subtopic page
Weight: 10
Url: /maintopic-subtopic1
… and in the markdown body, specify the shortcode like:
{{< putsubmenu >}}
In the code I’m trying to get the current page to highlight with:
{{ if $currentPage.IsMenuCurrent "mainsub" . }} is-active{{ end }}
… but, the is-active
class never gets set. This is likely a context issue, related to the fact that this is in a shortcode, but I’ve tried a bunch of variations in the meat of the range loop but, nothing is causing that class to get added.
The menu does work and appears on the page I add the above shortcode to, assuming the page has the menu added to the frontmatter.
Any advice appreciated, thanks!