从模板创建资源
In order to use Hugo Pipes function on an asset file containing Go Template magic the function resources.ExecuteAsTemplate
must be used.
The function takes three arguments, the resource object, the resource target path and the template context.
// assets/sass/template.scss
$backgroundColor: {{ .Param "backgroundColor" }};
$textColor: {{ .Param "textColor" }};
body{
background-color:$backgroundColor;
color: $textColor;
}
// [...]
{{ $sassTemplate := resources.Get "sass/template.scss" }}
{{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}