Can't use template function in markdown

I have a markdown page with an image defined in the front matter as follows:

---
...
images : ["/path/to/my/image.png"]
---

Within the body of my markdown, I am trying to insert that image using the front matter page variable:

<img src="{{ index (.Params.images) 0 }}"/>

However, the function is inserted verbatim in my HTML and doesn’t seem to be parsed.

What am I doing wrong? Must I create a shortcode to do this first? This seems like a pretty common use case for it to be inbuilt.

Thanks!

That’s correct.

You can also use inline shortcodes:

config.toml:

enableInlineShortcodes = true

Your markdown file:

{{< images.inline >}}{{ index (.Page.Params.images) 0 }}{{< /images.inline >}}

This should work. I have never used inline shortcodes.

4 Likes

Inline shortcodes worked perfectly! Thank you!