Skip to content

Commit f597beb

Browse files
authored
Fix tabs: use page-level counter for unique group IDs (#817) (#818)
.Page.Store.Add is broken in Hugo 0.158+ (returns nil). Additionally, Hugo renders shortcodes bottom-up, so the parent tabs.html cannot pass data to child tab.html via .Store. Fix: - shortcode-id partial: replace .Page.Store.Add with explicit .Page.Store.Set + add, which works in Hugo 0.161+. - tab.html: the first child tab generates a page-unique ID via the partial and caches it on .Parent.Store for siblings. - tabs.html: remove broken .Store.Set "id" line. This avoids the .Parent.Ordinal collision when tabs are nested inside other shortcodes (details, columns, etc.). Fixes #817
1 parent 6d5d778 commit f597beb

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

layouts/_shortcodes/tab.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{{- $group := printf "tabs-%v" (.Parent.Store.Get "id") -}}
1+
{{- if not .Ordinal -}}{{- /* first tab sets group ID */ -}}
2+
{{- .Parent.Store.Set "id" (partial "docs/text/shortcode-id" .Parent) -}}
3+
{{- end -}}
4+
{{- $group := printf "tabs-%d" (.Parent.Store.Get "id") -}}
25
{{- $tab := printf "%s-%d" $group .Ordinal -}}
36
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
47
{{- /* remove whitespaces */ -}}

layouts/_shortcodes/tabs.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{- .Store.Set "id" (partial "docs/text/shortcode-id" .) -}}
21
{{- $attributes := partial "docs/text/mapper" (dict
32
"attributes" (cond .IsNamedParams .Params dict)
43
"merge" (dict

0 commit comments

Comments
 (0)