From 8d9ab1cffb4d0e5b0a7c70a01ad6c142952362a0 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Fri, 15 Feb 2019 23:38:37 -0500 Subject: New tmpl.Exec function Signed-off-by: Dave Henderson --- docs/content/functions/tmpl.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'docs') diff --git a/docs/content/functions/tmpl.md b/docs/content/functions/tmpl.md index 64a0bf64..f6da5f4d 100644 --- a/docs/content/functions/tmpl.md +++ b/docs/content/functions/tmpl.md @@ -7,6 +7,39 @@ menu: Functions for defining or executing templates. +## `tmpl.Exec` + +Execute (render) the named template. This is equivalent to using the [`template`](https://golang.org/pkg/text/template/#hdr-Actions) action, except the result is returned as a string. + +This allows for post-processing of templates. + +### Usage +```go +tmpl.Exec name [context] +``` + +```go +context | tmpl.Exec name +``` + +### Arguments + +| name | description | +|------|-------------| +| `name` | _(required)_ The template's name. | +| `context` | _(optional)_ The context to use. | + +### Examples + +```console +$ gomplate -i '{{define "T1"}}hello, world!{{end}}{{ tmpl.Exec "T1" | strings.ToUpper }}' +HELLO, WORLD! +``` +```console +$ gomplate -i '{{define "T1"}}hello, {{.}}{{end}}{{ tmpl.Exec "T1" "world!" | strings.Title }}' +Hello, World! +``` + ## `tmpl.Inline` **Alias:** `tpl` -- cgit v1.2.3