Unfortunately that doesn’t work and I receive a Hugo Server: Error:
execute of template failed: template: shortcodes/figure.html:7:21: executing "shortcodes/figure.html" at <$img.relPermalink>: can't evaluate field relPermalink in type resource.Resource
If I enter {{ $img.ResourceType }} in the figure shortcode template, the printed result is image, so it seems to me, that the resource type is ok.
What did I do wrong? How does it work? Thx in advance!
I fear I need some additional advice. Trying to make use of additional page resource attributes I fail again.
I did set a title in my front matter:
- name: foo
src: bar.jpg
title: Lorem ipsum
params:
caption: dolor est
[...]
Now I want to use it in my shortcode:
[...]
{{- if .Get "link" }}</a>{{ end -}}
<!-- {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}-->
{{- if or (or ($img.Title) (.Get "caption")) (.Get "attr") -}}
<figcaption>
<!-- {{ with (.Get "title") -}}-->
{{ with ($img.Title) -}}
<h4>{{ . }}</h4>
{{- end -}}
[...]
This again results in an error: unexpected EOF So probably I didn’t understand the syntax of the with clause correctly?
I later want to make use of the value dolor est by its key caption as well. I’m not sure where to look up the needed method. Probably there exists something like $img.Params "caption"?
(Hopefully) last thing missing: How can I get values of Params by its key? I did find https://github.com/gohugoio/hugo/blob/master/resources/resource/resourcetypes.go#L109 and I’m a little confused that no parameter is mentioned for the function Params(). Using $img.Params "caption" leads to the consistent error message wrong number of args for Params: want 0 got 1 but leaves me wondering how to access the value/how to use the key.
Excellent. One more thing. If you intend to display the image at its actual size, you don’t need to pass the dimensions when calling the shortcode. Once you have the image resource, the values are available as properties.