github.com/wynshop-open-source/gomplate@v3.5.0+incompatible/docs-src/content/functions/tmpl.yml (about)

     1  ns: tmpl
     2  title: template functions
     3  preamble: |
     4    Functions for defining or executing templates.
     5  funcs:
     6    - name: tmpl.Exec
     7      description: |
     8        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.
     9  
    10        This allows for post-processing of templates.
    11      pipeline: true
    12      arguments:
    13        - name: name
    14          required: true
    15          description: The template's name.
    16        - name: context
    17          required: false
    18          description: The context to use.
    19      examples:
    20        - |
    21          $ gomplate -i '{{define "T1"}}hello, world!{{end}}{{ tmpl.Exec "T1" | strings.ToUpper }}'
    22          HELLO, WORLD!
    23        - |
    24          $ gomplate -i '{{define "T1"}}hello, {{.}}{{end}}{{ tmpl.Exec "T1" "world!" | strings.Title }}'
    25          Hello, World!
    26    - name: tmpl.Inline
    27      alias: tpl
    28      description: |
    29        Render the given string as a template, just like a nested template.
    30  
    31        If the template is given a name (see `name` argument below), it can be re-used later with the `template` keyword.
    32  
    33        A context can be provided, otherwise the default gomplate context will be used.
    34      pipeline: false
    35      arguments:
    36        - name: name
    37          required: false
    38          description: The template's name.
    39        - name: in
    40          required: true
    41          description: The template to render, as a string
    42        - name: context
    43          required: false
    44          description: The context to use when rendering - this becomes `.` inside the template.
    45      examples:
    46        - |
    47          $ gomplate -i '{{ tmpl.Inline "{{print `hello world`}}" }}'
    48          hello world
    49        - |
    50          $ gomplate -i '
    51          {{ $tstring := "{{ print .value ` world` }}" }}
    52          {{ $context := dict "value" "hello" }}
    53          {{ tpl "T1" $tstring $context }}
    54          {{ template "T1" (dict "value" "goodbye") }}
    55          '
    56          hello world
    57          goodbye world