On Oct 20, 2010, at 11:34 PM, Amnu wrote:
> For some unknown reason said solution doesn't work anymore. I can't
> tell what I've done to break it, since I basically haven't done
> anything (yeah right...). Anyway, if using variable_provider is a
> better way to do it then I'll be glad to walk that path. The problem
> is, I don't even know where to start with that one...
>
> I found a another newsgroup entry by you (http://www.mail-archive.com/
> [email protected]/msg40849.html) which describes what you
> mean with "variable_provider". I followed those directions exactly.
> Still, the template will complain about "categories" not being known
> to it (which is the variable I want to be filled by the underlying SQL
> query).
>
> Would you please take the time and explain to me in detail how you
> would solve this problem using this "variable_provider" approach ? If
> I simply put "from app_cfg import base_config" and do
> "base_config.variable_provider()" this would be simply the code block
> solution I tried before with lots of indirection, would it not ? So
> this can't be what you pointed at. I know almost nothing about TG's
> interior so please include all necessary information.
A variable provider is a callable that will be invoked on every request before
the template is rendered to enrich the namespace of the template.
It is configured in the <yourapp>/config/app_cfg.py file by a line like this:
def variable_provider():
return dict(categories=["apple", "banana", "ruby"])
base_config.variable_provider = variable_provider
Now obviously you would rather import your variable_provider from somewhere
else. But you get the drift. Please note the missing parentheses on the
configuration line - it's a *callback*!!
Now in every template a controller renders, the name "categories" is defined,
together with whatever you returned from the controller action of course. So to
prevent name-clashes, you might consider using something more unique.
Diez
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.