I was reading more about the new features added a few versions ago to see if some could improve the way I was managing CSS/JS and found this topic
I implemented it slightly different from the code posted just because my array of files is in a FrontMatter Parameter:
some-page.en.md
include:
footer:
js:
- /src/js/components/footable.core.min.js
- /src/js/components/footable.paging.min.js
- /src/js/components/footable.sorting.min.js
- /src/js/components/jquery.whensync.min.js
footer.html
{{ $.Scratch.Set "js" slice }}
{{ $.Scratch.Add "js" (resources.Get "/src/js/components/jquery.min.js" ) }}
{{ with $params.include.footer.js }}
{{ range . }}
{{ $.Scratch.Add "js" (resources.Get . ) }}
{{ end }}
{{ end }}
{{ $.Scratch.Add "js" (resources.Get "/src/js/some-code-that-must-go-after-everything.js" ) }}
{{ $js := $.Scratch.Get "js" | resources.Concat "/assets/js/chaotic.js" | minify | fingerprint }}
After the {{ with }}
block, if I debug the Scratch I’ve built, as expected, I have an array of Resources:
[Resource(javascript: src/js/components/jquery.min.js) Resource(javascript: src/js/components/footable.core.min.js) Resource(javascript: src/js/components/footable.paging.min.js) Resource(javascript: src/js/components/footable.sorting.min.js) Resource(javascript: src/js/components/jquery.whensync.min.js) Resource(javascript: /src/js/some-code-that-must-go-after-everything.js)]
But when debugging $js
or even reading the generated file, all generated resources coming from FrontMatter Parameter added during the iteration are not there. Plus, I have this error:
{0xc04215ddd0 <nil> 0xc04c710290 {{0 0} 0} <nil> {{0 0} 0} { map[]} 0xc04e1c3550}
And, obviously, it doesn’t work