So I have another noobish question about accessing data and passing it to inline JS
I want to pass all the file names to a javascript array. But I’m not getting the syntax right.
{{ $sb := $.Site.Data.sketchbook }}
{{ with $sb }}
{{ range .resources }}
{{ $output := slice .filename }}
{{ end }}
{{ end }}
<script type="text/javascript">
const sketchbook = [ {{ $output }}];
console.log(sketchbook);
</script>
My JSON file is shaped like this:
{
"resources": [
{
"url": "https://example.com/mysketch.png"
"other": "anotherthing",
"filename": "mysketch",
"alt": "the alt text",
},
{
"url": "https://example.com/mydifferentSketch.webp"
"other": "anotherthing",
"filename": "mydifferentSketch",
"alt": "the alt text",
},
]
}
How can I properly get the filenames, and insert them into the JS array as strings?
Thanks!