Skip to content

Proposal: Add "functions" to templates #2084

@technosophos

Description

@technosophos

I've been trying to come up with a way to call templates like functions (with arguments).

So far, the best I've been able to do is:

{{ include "some.template" (dict "NAME" "value") }}

Would it be helpful to simulate a Bash-like function call like this?

# Execute a template as if it were a function that takes arguments.
{{ func "some.template" $param $param2 }}

This could be used as a way to call templates that look like this:

{{ define "some.template" }}
  # Arguments are passed in using an Args array.
  {{ $arg1 := index .Args 0 }}
  {{ $arg2 := index .Args 1 }}
  # Do something
{{ end }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions