The expr attribute is used in the <al-if> and <al-elif> tags to specify a test expression. The expression is evaluated when the template is executed.
If the text expression in the expr attribute of the
<al-if> tag evaluates to a TRUE value then the
enclosed content up to either the next <al-elif> or
<al-else> tag will be executed.
For example:
>>> import albatross
>>> ctx = albatross.SimpleContext('.')
>>> ctx.locals.a = 10
>>> albatross.Template(ctx, '<magic>', '''
... <al-if expr="a < 15">
... a (<al-value expr="a">) is less than 15.
... <al-else>
... a (<al-value expr="a">) is greater than or equal to 15.
... </al-if>
... ''').to_html(ctx)
>>> ctx.flush_content()
a (10) is less than 15.
If the expression in the expr attribute of the
<al-if> tag evaluates FALSE then the enclosed content
following the <al-else> tag is executed.
For example:
>>> import albatross
>>> ctx = albatross.SimpleContext('.')
>>> ctx.locals.a = 20
>>> albatross.Template(ctx, '<magic>', '''
... <al-if expr="a < 15">
... a (<al-value expr="a">) is less than 15.
... <al-else>
... a (<al-value expr="a">) is greater than or equal to 15.
... </al-if>
... ''').to_html(ctx)
>>> ctx.flush_content()
a (20) is greater than or equal to 15.
The <al-elif> tag is used to chain a number of expression
that are tested in sequence. The first test that evaluates
TRUE determines the content that is executed.
For example:
>>> import albatross
>>> ctx = albatross.SimpleContext('.')
>>> ctx.locals.a = 30
>>> albatross.Template(ctx, '<magic>', '''
... <al-if expr="a < 15">
... a (<al-value expr="a">) is less than 15.
... <al-elif expr="a < 25">
... a (<al-value expr="a">) is greater than or equal to 15 and less than 25.
... <al-elif expr="a < 35">
... a (<al-value expr="a">) is greater than or equal to 25 and less than 35.
... <al-else>
... a (<al-value expr="a">) is greater than or equal to 25.
... </al-if>
... ''').to_html(ctx)
>>> ctx.flush_content()
a (30) is greater than or equal to 25 and less than 35.