Is stdvars and turbogears.view.variableProviders a per session/thread
one ? Or in other words, if I register a function to variableProviders,
would the function see cherrypy.session when it is called ?
My usage(as mentioned in another thread) is that I have a header
template that is being included in all templates. This template
contains some user information(typical like gmail/yahoo mail) that
depends on the current logon user.
Currently, I use a decorator before turbogears.expose so it would
"enrich" the returned dict and pass it on to turbogears.expose. But
this can be ugly when I have say 50 such functions, especially when I
have yet another check_login wrapper.
While a filter seems to be the right way, there are cases where not all
links need authentication, say the about page, the license page, the
contact page etc. But if it is done on a per page way(what I am doing
right now), it would happen that one function miss the decorator, it
has problem you highlighted.
Beside, the problem of filter is that the look can be ugly and not in
the same scheme as the app. For example, HTTP has its own
authentication protocol but very few people use it in application
because it looks odd.
Kid belongs to the family of template languages that assume you have
some type of code that's passing data to the template, and that this is
where it's best handled. ZPT is in the family of template languages
that assume the template is self-contained and usable by itself. (Btw,
it's TALES, not TAL that defines "exists:".)
But beyond that, Kid is a DSL to generate Python code that produces XML
output. It might make more sense to ask why Python doesn't have Perl's
'defined()', since Kid just exposes Python here. :) In contrast, the
TALES expression language is intended to support "web-ish" things as
well as pure Python.
The tradeoff between Kid and a DSL that defines its own expression
language (like ZPT or PWT) is that with Kid you already know the
language, but the custom language is probably easier to use for
anything that the DSL was designed to work well for. So Kid is maybe
more flexible than ZPT or PWT in this area, but potentially harder to
use as a result.
The tradeoff really has to get resolved in the wrapper code. If I were
going to do a lot with Kid, I'd probably end up creating wrapper code
that managed this stuff so the template could just do 'py:if="foo is
not None"' or 'py:if="have_foo"' and not worry about variables maybe
not existing. More specifically, I'd make it so I didn't have to write
a boilerplate wrapper for each and every template. At some point I'll
probably do this for peak.web, so that I can replace PWT with Kid.