Within a shortcode I’m trying to range over an array defined in the frontmatter but get only error messages if I’m trying to access the fields.
Here’s a stripped down version of the frontmatter I’m using:
---
title: A demo post
gallery: [
{ thumbnail: thumb1.jpg, "img1.jpg" },
{ thumbnail: thumb2.jpg, "img2.jpg" },
{ thumbnail: thumb3.jpg, "img3.jpg" }
]
---
Inside the shortcode a loop should range over gallery
and create a list with thumbnails:
<ul>
{{ range $.Params.gallery }}
<li><img src="{{ .thumbnail }}"></li>
{{ end }}
</ul>
But the console only shows error messages. Even trying to access the title of the post via {{ .Title }}
or {{ $.Params.title }}
doesn’t seem to work. With this simpler example I get the following error:
ERR: template: theme/shortcodes/gallery.html:3:8: executing “theme/shortcodes/gallery.html” at <$.Params.title>: can’t evaluate field title in type interface {}