Using hugo templates ({{) in markdown file

Is it possible to use template syntax (say {{ .Params... }} or {{ range ... }}) in a markdown post file?

I am trying to use a shortcode (say figure) in a post over an array of items (possibly from the params in the config file)

You can enable Inline Shortcodes

1 Like

Thanks for the link.

While I was able to enable inline short codes and use say <figure> itself in the post markdown file. I am not still able to use function like {{ range }}.

What I am trying to do is along these lines:

{{ range $index, $element := .Site.Params }}
{{< figure src="{{ $element }}" title="Image {{ $index }}" >}}
{{ end }}

However, it is rendered as follows:

image

The inner body of inline shortcodes is shortcode template context, you cannot call shortcodes i.e.
{{< figure >}} inside the body of inline shortcodes.

Not sure if I explained it right but I was try to explain the following:

In my post (markdown file), I am able to use {{<figure ...}} standalone. So enableInlineShortCodes = true worked. But {{ range ... }} does not work irrespective of what’s inside the range block - another shortcode or simple text.

calling a {{< figure ... >}} shortcode in markdown is normal usage of shortcode.
Inline Shortcodes is like this:

example defining inline shortcode template with name my_shortcode.

<!-- post.md -->

{{< my_shortcode.inline >}}

<pre>
{{ range $index, $element := .Site.Params }}
  {{ $index }} : {{ $element }}
{{ end }}
</pre>

{{< /my_shortcode.inline >}}