Differences between revisions 2 and 3
Revision 2 as of 2003-07-02 16:21:18
Size: 1894
Editor: dsl093-191-107
Comment:
Revision 3 as of 2011-02-15 06:05:17
Size: 1894
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

What happened to the context.locals

In a template the scope for all data references is context.locals, i.e. any reference to a variable called 'my_name' actually means context.locals.my_name. Publishing objects for use by the template means storing them in ctx.locals.

expr="name.value()" ... Why isn't it just name?

Here's the important bit in the documentation from section 5.3.7, "http://www.object-craft.com.au/projects/albatross/albatross/tag-for.html".

  • "The tag uses an instance of the ListIterator identified in the local namespace by the iter attribute to iterate over the sequence defined by the expression in the expr attribute."

If you look at ListIterator's methods it will probably make more sense now. It is ListIterator that makes the paging possible and the index() can be used for things like colouring alternate rows, i.e. name.index()%2 and 'red' or 'green'.

By the way, Dave has only just updated this bit of documentation based on feedback on the list so don't feel bad about missing the importance of ListIterator. It was documented but it was not as clear as it could have been.

why isn't it environ[name.value()].value()

So, why isn't the .value() needed on the end? Hopefully you now understand that:

  • "name" is a ListIterator created by the <al-for> tag to iterate

    • over the items in "keys"
  • "name.value()" is the current item from "keys"
  • "environ" when inside the template refers to the same dictionary
    • as "ctx.locals.environ" in the python code.

So all "environ[name.value()]" is actually doing is getting the value of the item in environ that has a key name.value(). The <al-value> tag has no need to create anything like the ListIterator as all it does is print some text to the page.

Parent: PuzzledAboutBitsAndPieces

None: TemplateContext (last edited 2011-02-15 06:05:17 by localhost)