Hi, I (again) need some help: So I did create my own figure shortcode to use page ressources. I now can use pictures as page ressources I define in the front matter and then use the figure shortcode within the markdown. That works well for index files (_index.md
) within branch bundles, but fails for other content files (content1.md
, content2.md
, ect.) within the branch bundle. If I try to call the figure shortcode within content1.md
I receive following error message:
"/project/content/foo/content1.md:29:1": failed to render shortcode "figure": failed to process shortcode: "/project/themes/bar/layouts/shortcodes/figure.html:2:19": execute of template failed: template: shortcodes/figure.html:2:19: executing "shortcodes/figure.html" at <$img.Params.Get>: nil pointer evaluating resource.Resource.Params
The offending line in the figure.html
shortcode is:
{{- if or ($img.Params.Get "caption") ($img.Params.Get "attr") -}}<p>
What did I do wrong? How to solve the issue?
figure shortcode template:
{{ $img := $.Page.Resources.GetMatch (.Get "src")}}
<figure{{ with $img.Params.Get "class" }} class="{{ . }}"{{ end }}>
{{- if $img.Params.Get "link" -}}
<a href="{{ $img.Params.Get "link" }}"{{ with $img.Params.Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end }}
<img src="{{ $img.RelPermalink }}"
{{- if or ($img.Params.Get "alt") ($img.Params.Get "caption") }}
alt="{{ with $img.Params.Get "alt" }}{{ . }}{{ else }}{{ $img.Params.Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with $img.Params.Get "width" }} width="{{ . }}"{{ end -}}
{{- with $img.Params.Get "height" }} height="{{ . }}"{{ end -}}
/> <!-- Closing img tag -->
{{- if $img.Params.Get "link" }}</a>{{ end -}}
{{- if or (or ($img.Title) ($img.Params.Get "caption")) ($img.Params.Get "attr") -}}
<figcaption>
{{ with ($img.Title) -}}
<h4>{{ . }}</h4>
{{- end -}}
{{- if or ($img.Params.Get "caption") ($img.Params.Get "attr") -}}<p>
{{- $img.Params.Get "caption" | markdownify -}}
{{- with $img.Params.Get "attrlink" }}
<a href="{{ . }}">
{{- end -}}
{{- $img.Params.Get "attr" | markdownify -}}
{{- if $img.Params.Get "attrlink" }}</a>{{ end }}</p>
{{- end }}
</figcaption>
{{- end }}
</figure>
font matter of content1.md
:
resources:
- name: myressource
src: myressource.jpeg
title: MyRessource
params:
caption: Lorem ipsum
width: 100%
alt: dolor est
The figure shortcode call within content1.md
:
{{<figure src="myressource" >}}
Directory/file structure:
content/
βββ foo
β βββ _index.md
β βββ content1.md
β βββ myressource.jpeg
Any help appreciated. Many thanks in advance!