Skip to content

Commit 52adf59

Browse files
Allow parameters inside the shortcode
1 parent 56b54a5 commit 52adf59

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

layouts/shortcodes/figure.html

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,31 @@
3939

4040
*/}}
4141

42-
{{- $figure := .Inner | transform.Unmarshal -}}
42+
{{- $useParams := true -}}
43+
{{- $figure := dict -}}
44+
45+
{{- if strings.TrimSpace .Inner -}}
46+
{{- if not .IsNamedParams -}}
47+
{{- $useParams = false -}}
48+
{{- $figure = .Inner | transform.Unmarshal -}}
49+
{{- end -}}
50+
{{- end -}}
51+
52+
{{/* If we're using params, collect them. */}}
53+
{{- if $useParams -}}
54+
{{- range $key, $value := .Params -}}
55+
{{- $figure = merge $figure (dict $key $value) -}}
56+
{{- end -}}
57+
{{- end -}}
58+
4359
{{- $align := default "default" $figure.align -}}
4460
{{- $id := printf "id%03d" $.Ordinal -}}
61+
4562
<figure class="align-{{ $align }}" id="{{ $id }}">
46-
{{- $m := newScratch -}}
47-
{{- $m.Set "image" $figure -}}
48-
{{- $m.SetInMap "image" "align" "center" -}}
49-
{{ partial "_elements/image.html" (dict "data" $m.Values.image) }}
63+
{{/* Create a clean copy of figure data with align center for image */}}
64+
{{- $image := merge $figure (dict "align" "center") -}}
65+
{{ partial "_elements/image.html" (dict "data" $image) }}
66+
5067
<figcaption>
5168
{{- with $figure.title -}}
5269
<strong class="caption-title">{{ . }}</strong><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a><br>

0 commit comments

Comments
 (0)