hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

resource-from-template.md (1018B)

    1 ---
    2 title: Creating a resource from template
    3 linkTitle: Resource from Template
    4 description: Hugo Pipes allows the creation of a resource from an asset file using Go Template.
    5 date: 2018-07-14
    6 publishdate: 2018-07-14
    7 lastmod: 2018-07-14
    8 categories: [asset management]
    9 keywords: []
   10 menu:
   11   docs:
   12     parent: "pipes"
   13     weight: 80
   14 weight: 80
   15 sections_weight: 80
   16 draft: false
   17 ---
   18 
   19 In order to use Hugo Pipes function on an asset file containing Go Template magic the function `resources.ExecuteAsTemplate` must be used.
   20 
   21 The function takes three arguments: the resource target path, the template context, and the resource object.
   22 
   23 ```go-html-template
   24 // assets/sass/template.scss
   25 $backgroundColor: {{ .Param "backgroundColor" }};
   26 $textColor: {{ .Param "textColor" }};
   27 body{
   28 	background-color:$backgroundColor;
   29 	color: $textColor;
   30 }
   31 // [...]
   32 ```
   33 
   34 
   35 ```go-html-template
   36 {{ $sassTemplate := resources.Get "sass/template.scss" }}
   37 {{ $style := $sassTemplate | resources.ExecuteAsTemplate "main.scss" . | resources.ToCSS }}
   38 ```