Selecting file from data folder based on shortcode parameter

Hello!

I have multiple csv files in my data folder.
I’d like to use a shortcode to pull in the content of one of the files.
I’d like to be able to select which file to use based on a parameter I specify when adding the shortcode, but I’m stuck with how to achieve that within the shortcode.

So if users enter {{< content a >}} for example, I’d like to display the content of a.json from my data folder. If they say {{< content b >}}, then I’d pull in b.json, etc. My question is, what do I need to add to my shortcode to be able to select the specified file?

layouts/shortcodes/content.html

{{ $data := index site.Data (.Get 0) }}
<pre>{{ jsonify (dict "indent" "  ") $data }}</pre>

See https://gohugo.io/functions/index-function/

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.