Loop across javascript path and integrity variables

I’d like to loop across two variables, path and integrity, to insert external javascripts to baseof.html.

{{if .Site.Params.js}}
{{- range .Site.Params.js }}
<script src= "{{ .Site.Params.js | absURL | safeJS}}.js">  integrity= "{{ .Site.Params.integrity | absURL | safeCSS}}" crossorigin="anonymous" defer></script>
{{- end }}
{{ end }}

The code above can manage the path (better with just . ), but not the integrity parameters.

How to achieve this?

Struture your data as array of object (map).
in TOML we can write it like this:

[[params.js]]
 src = "https://link-to-javascript"
 integrity="dansdy9asdasn8dasdi"

[[params.js]]
 src = "https://link-to-javascript2"
 integrity="dsan7d78sad7yasd"

Then you can write like this in your template:

{{if .Site.Params.js}}
{{- range .Site.Params.js }}
<script src="{{ .src | absURL | safeJS}}" integrity="{{ .integrity }}" crossorigin="anonymous" defer></script>
{{- end }}
{{ end }}

Perfect. Thanks.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.