5.5.4 <al-expand>

The <al-expand> tag is used to expand a previously defined macro.

You can pass macro expansions as arguments to other macros.

>>> import albatross
>>> ctx = albatross.SimpleContext('.')
>>> albatross.Template(ctx, '<magic>', '''
... <al-macro name="red">
... <font color="red"><al-usearg></font>
... </al-macro>
... 
... <al-macro name="bold"><b><al-usearg></b></al-macro>
... ''').to_html(ctx)
>>> ctx.flush_content()
>>> albatross.Template(ctx, '<magic>', '''
... <al-expand name="red">more <al-expand name="bold">spam</al-expand> please</al-expand>
... <al-expand name="red"><al-expand name="bold">more spam please</al-expand></al-expand>
... ''').to_html(ctx)
>>> ctx.flush_content()
<font color="red">more <b>spam</b> please</font>
<font color="red"><b>more spam please</b></font>

All arguments to macros are executed each time they are used in the macro definition. This means that you need to be aware of side effects when using arguments more than once inside a macro.

>>> import albatross
>>> ctx = albatross.SimpleContext('.')
>>> albatross.Template(ctx, '<magic>', '''
... <al-macro name="yummy">
...  <al-for iter="i" expr="range(3)">
...   <al-usearg whitespace="indent">
...  </al-for>
... </al-macro>
... ''').to_html(ctx)
>>> ctx.locals.food = 'spam'
>>> albatross.Template(ctx, '<magic>', '''
... <al-expand name="yummy">
...  <al-exec expr="food = food + '!'">
...  <al-value expr="food">
... </al-expand whitespace>
... ''').to_html(ctx)
>>> ctx.flush_content()
spam! spam!! spam!!! 



Subsections