ns: tmpl title: template functions preamble: | Functions for defining or executing templates. funcs: - name: tmpl.Exec released: v3.3.0 description: | Execute (render) the named template. This is equivalent to using the [`template`](https://pkg.go.dev/text/template/#hdr-Actions) action, except the result is returned as a string. This allows for post-processing of templates. pipeline: true arguments: - name: name required: true description: The template's name. - name: context required: false description: The context to use. examples: - | $ gomplate -i '{{define "T1"}}hello, world!{{end}}{{ tmpl.Exec "T1" | strings.ToUpper }}' HELLO, WORLD! - | $ gomplate -i '{{define "T1"}}hello, {{.}}{{end}}{{ tmpl.Exec "T1" "world!" | strings.Title }}' Hello, World! - name: tmpl.Inline alias: tpl released: v3.3.0 description: | Render the given string as a template, just like a nested template. If the template is given a name (see `name` argument below), it can be re-used later with the `template` keyword. A context can be provided, otherwise the default gomplate context will be used. pipeline: false arguments: - name: name required: false description: The template's name. - name: in required: true description: The template to render, as a string - name: context required: false description: The context to use when rendering - this becomes `.` inside the template. examples: - | $ gomplate -i '{{ tmpl.Inline "{{print `hello world`}}" }}' hello world - | $ gomplate -i ' {{ $tstring := "{{ print .value ` world` }}" }} {{ $context := dict "value" "hello" }} {{ tpl "T1" $tstring $context }} {{ template "T1" (dict "value" "goodbye") }} ' hello world goodbye world - name: tmpl.Path released: v3.11.0 description: | Output the path of the current template, if it came from a file. For inline templates, this will be an empty string. Note that if this function is called from a nested template, the path of the main template will be returned instead. pipeline: false rawExamples: - | _`subdir/input.tpl`:_ ``` this template is in {{ tmpl.Path }} ``` ```console $ gomplate -f subdir/input.tpl this template is in subdir/input.tpl ``` - name: tmpl.PathDir released: v3.11.0 description: | Output the current template's directory. For inline templates, this will be an empty string. Note that if this function is called from a nested template, the path of the main template will be used instead. pipeline: false rawExamples: - | _`subdir/input.tpl`:_ ``` this template is in {{ tmpl.Dir }} ``` ```console $ gomplate -f subdir/input.tpl this template is in subdir ```