Pre-Built Functions (Macros)

The Jinja Template has pre-built functions to facilitate rapid template modification. In Jinja2 parlance, functions are called macros. We know that “macro” is a dirty word in infosec with regards to MS Office. These are NOT Microsoft macros – they are simply functions that have an unfortunate name. The pre-built functions are easy to use. You will simply call the function by its name and provide any required or optional arguments to modify behavior. The format of a function is:
Arguments are data that you pass to the function. Arguments may be values of any data type, e.g. string (enclosed in quotes), Boolean, integer, etc. Some arguments are mandatory and some are optional. We will identify which (if any) arguments are mandatory in the discussion of each function.
Functions may have pre-defined values to use if no arguments are passed when calling the function.
Arguments may be optional, but may become mandatory if you desire to change the default value of any argument beyond position 1. For example, using the above example,
{{p my_function_name() }}
May be a valid function call, even though it has no arguments (note empty parens after function name). There may be default values for both arguments defined in the function, or they may only impact the function’s behavior if used. However, arguments for positions 2 and beyond may only be passed if arguments are passed for previous positions.
In the above example, the argument in position 1 may have a default value (“foobar”) defined in the function that I wish to use. But if I want to change the argument in position 2, I still need to pass an argument for position 1 (even if it matches the default):
{{p my_function_name(“foobar”, true) }}