Pass Data to Content Markdown Files in Hugo
Here's a simple shortcode template that passes in any data file within your Hugo blog's data directory into any page in your content directory.
layouts/shortcodes/data.html
:
{{ $data := index $.Site.Data (.Get "datafile") }}
<script>
window[{{ .Get "var" }}] = {{ $data }};
</script>
content/posts/example.md
:
---
title: "Data"
---
{{<data var="myData" datafile="data_file_name">}}
You can now access myData
in any other scripts attached to your markdown page.