This tag allows you to evaluate simple expressions and write the result to output. The expression specified in the expr attribute is evaluated and written as a string to the output.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> albatross.Template(ctx, '<magic>', ''' ... hash('spam') is <al-value expr="hash('spam')" whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() hash('spam') is 1626740519
If the noescape attribute is present then the value is not escaped. Only use this attribute when you are sure that the result of the expression is safe. Without this attribute all &, <, >, and " are escaped.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> ctx.locals.field = '<img src="http://rude.pictures.r.us/">' >>> albatross.Template(ctx, '<magic>', ''' ... Safe: <al-value expr="field" whitespace> ... Oops: <al-value expr="field" noescape whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() Safe: <img src="http://rude.pictures.r.us/"> Oops: <img src="http://rude.pictures.r.us/">
If a date attribute is specified then the enclosed format string is passed to the Python time.strftime() function along with the result of the expression in the expr attribute. The result of time.strftime() is then written to the output.
For example:
>>> import albatross >>> import time >>> ctx = albatross.SimpleContext('.') >>> albatross.Template(ctx, '<magic>', ''' ... The time is <al-value expr="time.mktime((2001,12,25,1,23,34,0,0,-1))" ... date="%H:%M:%S" whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() The time is 01:23:34
When the lookup attribute is specified the result of the expression is used to retrieve content from the lookup table named in the lookup attribute. This is a very useful way to separate the internal representation of program value from the presentation of that value.
For example:
>>> import albatross >>> ctx = albatross.SimpleContext('.') >>> ctx.locals.simple = 0 >>> ctx.locals.works = 1 >>> albatross.Template(ctx, '<magic>', ''' ... <al-lookup name="bool"><al-item expr="0">FALSE</al-item>TRUE</al-lookup> ... Simple: <al-value expr="simple" lookup="bool" whitespace> ... Works: <al-value expr="works" lookup="bool" whitespace> ... ''').to_html(ctx) >>> ctx.flush_content() Simple: FALSE Works: TRUE
Please refer to the <al-lookup> tag reference for an explanation that tag and more complex examples.