Can I pass a dict to a shortcode?


I have a picture partial that generates images for mobile, tablet, desktop and so forth.
I would like to use this partial in my page templates or layouts, as well as in markdown files.
The partial accepts a dictonary as so:

{{ partial "helpers/picture.html" (dict "url" "images/chapter-3/hero-bg.svg" "alt" "Shapes Background" "lazy" true) }}

To minimise duplicative code, I noticed I could do the following in shortcodes/partial.html

{{ partial (.Get 0) (.Get 1) }}

However I cannot call the shortcode successfully.

{{< partial "helpers/picture.html" (dict "url" "images/chapter-3/hero-bg.svg" "alt" "Shapes Background" "lazy" true) >}}

Is there an easier way without having two seperate markup files for displaying pictures?

No, you cannot.

You’ll have to pass the individual args to the shortcode, then build a map, then pass the map to the partial.

You can!

In content call shortcode named “partial” with named params:

{{< partial template="path/to/partial/some-partial-template" show="1" >}}

In ./shortcodes/partial.html:

{{ partial (.Get "template") .Params }}

In ./partials/path/to/partial/some-partial-template.html


will show


You will still have the utility “template” named param though…