If this attribute is set, the current value of the iterator (as returned by value() will be saved to a variable of this name in the local namespace.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> albatross.Template(ctx, '<magic>', ''' ... <al-for vars="v" expr="range(15)" whitespace="indent"> ... <al-value expr="v"> ... </al-for whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
If the attribute is set to a comma separated list of variables, the iterator value will be unpacked into these variables. The iterator values must iterable in this case (typically a tuple or list). If there are more variables listed than there are values to be unpacked, then the unused variables are left unchanged. Conversely, if there are more values than variables, only the values with corresponding names will be unpacked.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> ctx.locals.items = [(1.23, 'Red'), (4.71, 'Green'), (0.33, 'Blue')] >>> albatross.Template(ctx, '<magic>', ''' ... <al-for vars="price, label" expr="items"> ... <al-value expr="'$%0.2f' % price"> <al-value expr="label" whitespace> ... </al-for> ... ''').to_html(ctx) >>> ctx.flush_content() $1.23 Red $4.71 Green $0.33 Blue