Using Built-in Helpers
The template rendering commands include a set of built-in helper functions to assist you with the rendering process.
Functions
include
This function allows you to invoke your own custom helper functions.
e.g.
This function can also be used to render a file.
e.g.
The path to template file to render is relative to the parent template file.
os_writefile
Write a file to the output directory
The destination path is relative to the output directory. ( ".." or absolute paths are not allowed)
This function outputs the destination file path.
e.g.
os_copyfile
Copies files to the output directory. This function outputs the destination file path as a string.
The destination path is relative to the output directory ( ".." or absolute paths are not allowed)
The source path is relative to the main template file directory ( ".." or absolute paths are not allowed)
e.g.
os_getenvs
Gets all environment variables as a dictionary
e.g.
os_getenv
Gets the value of the specified env var
e.g.
slug_make
Converts string to a slug
e.g.
The example above outputs "my-api-proxy"url_parse
Parse a URL into its parts.
This function outputs a net.URL struct.
e.g.
blank
Outputs empty string. This is useful to consume the output of another function.
e.g.
deref
Dereferences the input pointer.
fmt_printf
Write to stdout during the rendering process. This function is useful for so called "printf" debugging.
For example, you can use it to trace the template rendering as it runs. Or, can also use it to dump values to stdout in order to see the contents.
e.g.
Libraries
Sprig
This library contains a lot of useful functions for string manipulation, accessing maps, lists, encoding, and more.
Functions from Sprig library are available during rendering.
e.g.