mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2025-07-17 03:51:56 +00:00
Rewrite tabs shortcode to make them simpler
This commit is contained in:
parent
1bda9fb34d
commit
f8a0e8976b
@ -1,12 +1,9 @@
|
|||||||
{{ if .Parent }}
|
{{- $group := printf "tabs-%d" .Parent.Ordinal -}}
|
||||||
{{ $name := .Get 0 }}
|
{{- $tab := printf "%s-%d" $group .Ordinal }}
|
||||||
{{ $group := printf "tabs-%d" .Parent.Ordinal }}
|
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
|
||||||
|
<label for="{{ $tab }}">
|
||||||
{{ if not (.Parent.Scratch.Get $group) }}
|
{{- .Get 0 -}}
|
||||||
{{ .Parent.Scratch.Set $group slice }}
|
</label>
|
||||||
{{ end }}
|
<div class="book-tabs-content markdown-inner">
|
||||||
|
{{- .Inner -}}
|
||||||
{{ .Parent.Scratch.Add $group (dict "Name" $name "Content" .Inner) }}
|
</div>
|
||||||
{{ else }}
|
|
||||||
{{ errorf "%q: 'tab' shortcode must be inside 'tabs' shortcode" .Page.Path }}
|
|
||||||
{{ end}}
|
|
||||||
|
@ -1,14 +1,3 @@
|
|||||||
{{- if .Inner }}{{ end -}}
|
|
||||||
{{- $group := printf "tabs-%d" .Ordinal -}}
|
|
||||||
|
|
||||||
<div class="book-tabs">
|
<div class="book-tabs">
|
||||||
{{- range $index, $tab := .Scratch.Get $group -}}
|
{{ .Inner }}
|
||||||
<input type="radio" class="toggle" name="{{ $group }}" id="{{ printf "%s-%d" $group $index }}" {{ if not $index }}checked="checked"{{ end }} />
|
|
||||||
<label for="{{ printf "%s-%d" $group $index }}">
|
|
||||||
{{- $tab.Name -}}
|
|
||||||
</label>
|
|
||||||
<div class="book-tabs-content markdown-inner">
|
|
||||||
{{- .Content | safeHTML -}}
|
|
||||||
</div>
|
|
||||||
{{- end -}}
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user