Macros
macro — Macro definition
A macro is an open subroutine. Unlike a function, it executes within the current context of the caller. It has direct access to all variables in the calling scope.
Syntax
XML
<macro var="myMacro">
<!-- macro body — executes in caller's context -->
<output>Hello $name</output>
</macro>
When to use
Macros are ideal for:
- Template fragments
- Repetitive output patterns
- Simple utility routines where context overhead is unwanted
Warning: Macros can accidentally overwrite variables in the caller's scope.
expand — Expand macro
Invokes a macro.
Syntax
XML
<expand macro="macroName"/>
Example
XML
<set var="name">World</set>
<macro var="greet"><output>Hello $name</output></macro>
<expand macro="greet"/>
<!-- Hello World -->