mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Merge commit 'a024bc7d76fcc5e49e8210f9b0896db9ef21861a'
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: ExecuteAsTemplate
|
||||
linkTitle: Resource from template
|
||||
description: Creates a resource from a template
|
||||
description: Create a resource from a Go template, parsed and executed with the given context.
|
||||
categories: [asset management]
|
||||
keywords: []
|
||||
menu:
|
||||
@@ -9,30 +9,6 @@ menu:
|
||||
parent: hugo-pipes
|
||||
weight: 120
|
||||
weight: 120
|
||||
action:
|
||||
aliases: []
|
||||
returnType: resource.Resource
|
||||
signatures: [resources.ExecuteAsTemplate TARGETPATH CONTEXT RESOURCE]
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
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 target path for the created resource, the template context, and the resource object. The target path is used to cache the result.
|
||||
|
||||
```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" . | css.Sass }}
|
||||
```
|
||||
See the [`resources.ExecuteAsTemplate`](/functions/resources/executeastemplate/) function.
|
||||
|
Reference in New Issue
Block a user