Hi All, - Is it possible to concatenate 2 x JS files into an in-line script.
I’ve tried something like this but I can’t seem to get it to work:
{{- resources.Get := slice (resources.Get "../assets/js/all-menu-functions.js") (resources.Get "../assets/js/home-js.js") | resources.Concat "assets/js/home.js" | minify }}
<script>{{ .Content | safeJS }}</script>
{{ end }}
Thanks
A method cannot be used as the name of a variable. Also in Hugo variables are prefixed with the dollar sign e.g. $var
Please have a better look at the Asset Bundling example in the Hugo Pipes chapter of the documentation.
Yes I took a look at that previously.
But how do I get this content:
{{ $plugins := resources.Get “js/plugins.js” }}
{{ $global := resources.Get “js/global.js” }}
{{ $js := slice $plugins $global | resources.Concat “js/bundle.js” }}
into a tag like this in the html
<script>
concatenated inline JS here
</script>
Thanks,
bep
May 29, 2020, 8:11am
4
{{ $plugins := resources.Get “js/plugins.js” }}
{{ $global := resources.Get “js/global.js” }}
{{ $js := slice $plugins $global | resources.Concat “js/bundle.js” }}
<script>
{{ $js.Content | safeJS }}
</script>
6 Likes
Perfect! …Legend - Thanks
system
Closed
May 31, 2020, 11:41pm
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.