kbex
June 5, 2022, 5:19pm
1
when using resources.ExecuteAsTemplate on a css file i get an empty css file back.
hugo version:
v0.101.0-DEV-bfebd8c02cfc0d4e4786e0f64932d832d3976e92 linux/amd64 BuildDate=2022-06-01T10:54:16Z
radio-nav.css
sits in /assets/css/
this is the code i’m running
{{$css := resources.Get "css/radio-nav.css" | resources.ExecuteAsTemplate "css/radio-nav.css" . | fingerprint }}
<link rel="stylesheet" type="text/css" href="{{ $css.RelPermalink }}">
radio-nav.css - works well when i load it with partial
but i want to use resources.Get so i can pipe through fingerprint and have all the css files in the assets folder.
i’m not sure why ExecuteAsTemplate returns an empty file.
any pointers will be appreciated.
thanks
kbex
June 5, 2022, 9:37pm
3
does resources.ExecuteAsTemplate works only with SCSS ?
We need to see your git repository or a minimal test case that demonstrates the issue. You have not yet provided enough context.
1 Like
kbex
June 6, 2022, 11:19am
5
head.html
<head>
{{- if and (eq .Section "shop") (eq .Kind "page")}}
{{$css_template := resources.Get "css/template.css" }}
{{$css := $css_template | resources.ExecuteAsTemplate "css/radio-nav.css" . | resources.ToCSS | fingerprint}}
<link rel="stylesheet" type="text/css" href="{{ $css.RelPermalink }}">
{{end}}
</head>
template.css - sits in the assets folder
{{$x := .Resources.Match "images/*"}}
{{ $length := (len $x) }}
{{ $length = sub $length 1}}
{{- range $i, $x := .Resources.Match "images/*" -}}
#next-{{$i}}:checked ~ #step-{{$i}} ,#prev-{{$i}}:checked ~ #step-{{$i}} {display: none;}
{{if eq $i 0}}
#prev-{{$i}}:checked ~ #step-{{$length}} {display: grid;}
{{else}}
#prev-{{$i}}:checked ~ #step-{{sub $i 1}} {display: grid;}
{{end}}
{{if eq $i $length }}
#next-{{$i}}:checked ~ #step-0 {display: grid;}
{{else}}
#next-{{$i}}:checked ~ #step-{{add $i 1}} {display: grid;}
{{end}}
{{- end -}}
when template.css is piped through resources.ExecuteAsTemplate it comes back empty.
when i use the same code only with a partial instead (and place the template.css in partial folder). it works fine the partial processes the code i.e -
<head>
{{- if and (eq .Section "shop") (eq .Kind "page")}}
<style type="text/css">
{{ partial "template.css" . | safeCSS }}
</style>
{{end}}
</head>
am i using resources.ExecuteAsTemplate wrong ?
kbex
June 6, 2022, 12:32pm
6
ok, after some trial and error it seems that
adding the .Resources.Match “images/*” in the range is what broke it.
changing to seq, spits out the processed css.
easy workaround, but it looks like a bug (?).
{{$x := .Resources.Match "images/*"}}
{{ $length := (len $x) }}
{{ $length = sub $length 1}}
{{- range $i, $x := (seq 5 ) -}}
#next-{{$i}}:checked ~ #step-{{$i}} ,#prev-{{$i}}:checked ~ #step-{{$i}} {display: none;}
{{if eq $i 0}}
#prev-{{$i}}:checked ~ #step-{{$length}} {display: grid;}
{{else}}
#prev-{{$i}}:checked ~ #step-{{sub $i 1}} {display: grid;}
{{end}}
{{if eq $i $length }}
#next-{{$i}}:checked ~ #step-0 {display: grid;}
{{else}}
#next-{{$i}}:checked ~ #step-{{add $i 1}} {display: grid;}
{{end}}
{{- end -}}
EDIT:
not a bug, .Resources.Match "images/*
does match with different context
when using ExecuteAsTemplate.
how would i pass the correct context for ExecuteAsTemplate to be able to run .Resources.Match “images/*” ?
system
Closed
June 8, 2022, 3:16pm
8
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.