mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
a3535c8486
a4fa0d1d6 Typos and grammatical changes 513884600 Add hugo pipes documentation git-subtree-dir: docs git-subtree-split: a4fa0d1d641b2b3e27a91ae8b1a0a29be3c42ddf
38 lines
No EOL
1,016 B
Markdown
Executable file
38 lines
No EOL
1,016 B
Markdown
Executable file
---
|
|
title: Creating a resource from template
|
|
linkTitle: Resource from Template
|
|
description: Hugo Pipes allows the creation of a resource from an asset file using Go Template.
|
|
date: 2018-07-14
|
|
publishdate: 2018-07-14
|
|
lastmod: 2018-07-14
|
|
categories: [asset management]
|
|
keywords: []
|
|
menu:
|
|
docs:
|
|
parent: "pipes"
|
|
weight: 80
|
|
weight: 80
|
|
sections_weight: 80
|
|
draft: 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.
|
|
|
|
```go-html-template
|
|
// assets/sass/template.scss
|
|
$backgroundColor: {{ .Param "backgroundColor" }};
|
|
$textColor: {{ .Param "textColor" }};
|
|
body{
|
|
background-color:$backgroundColor;
|
|
color: $textColor;
|
|
}
|
|
// [...]
|
|
```
|
|
|
|
|
|
```go-html-template
|
|
{{ $sassTemplate := resources.Get "sass/template.scss" }}
|
|
{{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}
|
|
``` |