How to access a data file based on the current section? [SOLVED]

For each section of my website, I have an accompanying file in the /data/snippets/ folder. Those data files all have the same name as a section.

In my theme, I loop over the contents of the data file like so for the “post” section:

{{ range }}       
     <!-- ... -->
{{ end }}

Is it possible to insert the name of the section (.Section) in the range statement? If possible, I can prevent a lot of repetition in my code.


Got an idea that brought me a bit further:

{{ range (index .Site.Data.snippets .Section) }}
     <!--- --->
{{ end }}

This works in looping over the contents of the section’s data file in /data/snippets/, but the shuffle function fails now:

{{ range (index .Site.Data.snippets .Section) | shuffle | first 1}}
    <!-- --->
{{ end }}

wrong number of args for shuffle: want 1 got 0

{{ range (index .Site.Data.snippets .Section | shuffle) | first 1}}

1 Like

Thank you!