Using Custom Helpers
Sometimes it's useful to create your own custom helper functions that you can use during the template rendering process.
You can define helper functions within the main template file itself, or in separate helper files.
By default, the tool will look for a file named _helpers.tpl in the same directory as the template, and include it.
Alternatively, you can use the --include flag to specify one or more files containing helper functions.
Example
Below is a sample helper function. Let's see how to use it.
-
First, place this block inside a helper file (e.g.
my_helpers.tpl) -
Then, pass
--include ./my_helpers.tplto therender) command.
Finally, in order to invoke the custom helper function, use the {{ include ... }} built-in function from your main template.
e.g.
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