2019-10-21 08:22:28 +00:00
|
|
|
---
|
|
|
|
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.
|
|
|
|
|
2021-04-20 18:21:45 +00:00
|
|
|
The function takes three arguments: the resource target path, the template context, and the resource object.
|
2019-10-21 08:22:28 +00:00
|
|
|
|
|
|
|
```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 }}
|
2021-04-20 18:21:45 +00:00
|
|
|
```
|