hugo/content/en/hugo-pipes/resource-from-template.md
Bjørn Erik Pedersen a3535c8486 Squashed 'docs/' changes from cfe89ecbc..a4fa0d1d6
a4fa0d1d6 Typos and grammatical changes
513884600 Add hugo pipes documentation

git-subtree-dir: docs
git-subtree-split: a4fa0d1d641b2b3e27a91ae8b1a0a29be3c42ddf
2018-07-19 09:18:11 +02:00

1,016 B
Executable file

title linkTitle description date publishdate lastmod categories keywords menu weight sections_weight draft
Creating a resource from template Resource from Template Hugo Pipes allows the creation of a resource from an asset file using Go Template. 2018-07-14 2018-07-14 2018-07-14
asset management
docs
parent weight
pipes 80
80 80 false

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 }}