docs/content/en/functions/resources/ExecuteAsTemplate.md
The resources.ExecuteAsTemplate function returns a resource created from a Go template, parsed and executed with the given context, caching the result using the target path as its cache key.
Hugo publishes the resource to the target path when you call its Publish, Permalink, or RelPermalink methods.
Let's say you have a CSS file that you wish to populate with values from your project configuration:
body {
background-color: {{ site.Params.style.bg_color }};
color: {{ site.Params.style.text_color }};
}
And your project configuration contains:
{{< code-toggle file=hugo >}} [params.style] bg_color = '#fefefe' text_color = '#222' {{< /code-toggle >}}
Place this in your baseof.html template:
{{ with resources.Get "css/template.css" }}
{{ with resources.ExecuteAsTemplate "css/main.css" $ . }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
The example above:
The result is:
body {
background-color: #fefefe;
color: #222;
}