define

Defines macros, headers, and footers.

Syntax

define macro_name([arg_1, arg_2, ..., arg_n])

Input

Macro_name
The name of the macro.
Arg_1, arg_2, ..., arg_n
The list of arguments passed to the macro.

Example

Example 1
Template:
{define greeting(first, last)}

Dear {first} {last},

{enddefine}
{greeting("John", "Doe")}
Output:
Dear John Doe,
Example 2
Template:
{define header()}

Chapter 5 - Templex Functions

{enddefine}
{header()}
Output:
Chapter 5 - Templex Functions
Example 3
Template:
{define footer()}

Templex Programmer's Guide

{enddefine}
{footer()}
Output:
Templex Programmer's Guide

Comment

Macros are reusable segments of a template. They are useful in cases where the same series of template statements or text can be used repeatedly.

Macro definitions begin with a define statement and end with an enddefine statement. The define statement declares the name of the macro and any arguments it might have. Arguments are optional.

A macro is called using the same syntax as other Templex statements. When Templex encounters the macro name, the arguments are passed to the macro. Arguments are replaced left to right. Arguments missing parameters are replaced with null.

Macros must be defined before they are called.

Macros do not have local variables - they can reference any variable in the template.

There are two special reserved macro names: "header" and "footer." When defined in a template, they specify the page header and footer text. The contents of "header" are placed at the top of every page by default. The contents of "footer" are placed at the bottom of every page by default. If "header" and "footer" are not defined in a template, headers and footers do not appear on the pages.