The expression is specified in the expr attribute. It is
compiled using kind = 'exec'
and evaluated when the
template is executed.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> albatross.Template(ctx, '<magic>', ''' ... <al-exec expr=" ... results = [] ... for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... results.append('%d equals %d * %d' % (n, x, n/x)) ... break ... else: ... results.append('%d is a prime number' % n) ... "> ... <al-for iter="l" expr="results"> ... <al-value expr="l.value()" whitespace> ... </al-for> ... ''').to_html(ctx) >>> ctx.flush_content() 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3
If you need to include the same quote character used to enclose the
attribute value in your expression you can escape it using a backslash
(``'').
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> albatross.Template(ctx, '<magic>', r''' ... <al-exec expr="a = '\"'"> ... a = <al-value expr="a" whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() a = "