mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
985 B
985 B
Tag {macro}
Macros are comparable with functions in regular programming languages. They are useful to put often used HTML idioms into reusable elements to not repeat yourself.
{macro}
Macros can be defined in any template using tag {macro}
.
{macro plus($x, $y, $z=0)}
x + y + z = {$x + $y + $z}
{/macro}
{macro.plus x=$num y=100}
{macro plus($x, $y, $z=0)}
...
{macro.plus x=2 y=$y}
...
{/macro}
{import}
Macros can be defined in any template, and need to be "imported" before being used.
The above import call imports the "math.tpl" file (which can contain only macros, or a template and some macros),
and import the functions as items of the macro
namespace.
{import 'math.tpl'}
{macro.plus x=1 y=3}
Use another namespace instead of macro
{import 'math.tpl' as math}
...
{math.plus x=5 y=100}
{import [plus, minus, exp] from 'math.tpl' as math}