Skip to content

Using Custom Helpers

Sometimes it's useful to create your own custom helper functions that you can use during the template rendering process.

Use the --include flag to specify one or more files containing helper functions.

Note

You can pass the --include flag multiple times, or even use glob patterns to include multiple files.

Example

Below is a sample helper function. Let's see how to use it.

{{- define "say_hello" -}}
  Hello {{ $. }} !
{{- end -}}
  1. First, place this block inside a helper file (e.g. helper.tmpl)

  2. Then, pass --include ./helper.tmpl to the render) command.

Finally, in order to invoke the custom helper function, use the {{ include ... }} built-in function from your main template.

e.g.

Message: {{ include "say_hello" "World" }}

The engine will render the say_hello block separately, and include the output text wherever you put {{ include ... }} function.

For this example, the final rendered text will look like this

Message: Hello World !