I am trying to add a javascript file to my pipe that needs to be executed as template. Somehow it fails (of course) and I am not sure what exactly the problem is.
the pipe:
{{ $js1 := resources.Get "js/somefile.js" }}
{{ $js2 := resources.Get "js/someotherfile.js" }}
{{ $collection := slice $js1 $js2}}
{{ $template := "js/somecompletelydifferentfile.js" }}
{{ $js3 := resources.Get $template | resources.ExecuteAsTemplate $template . }}
{{ $collection = $collection | append ($js3) }}
{{ $js := $collection | resources.Concat "script.js" | resources.Minify | resources.Fingerprint "sha384" }}
the error:
Error:
Error building site:
failed to render pages: render of "page" failed: execute of template failed:
template:
_default/single.html:40:5: executing "_default/single.html" at <partial "footer" .>:
error calling partial:
execute of template failed:
template:
partials/footer.html:6:8: executing "partials/footer.html" at <partialCached "func/getJavascript.html" .>:
error calling partialCached: "/home/patrick/Projects/Hugo/dnb-hugo-garuda/layouts/partials/func/getJavascript.html:15:51":
execute of template failed:
template:
partials/func/getJavascript.html:15:51:
executing "partials/func/getJavascript.html" at <resources.ExecuteAsTemplate>:
error calling ExecuteAsTemplate:
type <nil> not supported in Resource transformations
That line 15 in getJavascript.html is the {{ $js3 := resources.Get $template | resources.ExecuteAsTemplate $template . }}
part of the partial.
I admit I never got executeAsTemplate running in any case, so I might have a total failure of understanding the underlying concept here, but what might be the error? I would assume whatever resources.Get returns should be the same type as what (resources.Get | executeAsTemplate) returns?
If not, how would you attempt the following:
- there is a list of js files that need executing
- there is another list of js files that don’t need executing
- all those files need to be concatenated, minified, postprocessed afterwards.