Is there any analog of django context processors in turbogears2? In tg1 was stdvars, but not in tg2 anymore.
Explaining: I need to have some template tags, avaible on each page, without obvious declaring in each controller.
Is there any analog of django context processors in turbogears2? In tg1 was stdvars, but not in tg2 anymore.
Explaining: I need to have some template tags, avaible on each page, without obvious declaring in each controller.
You have three possible solutions to achieve this.
First you can use
tg.tmpl_contextwhich is available inside every template astmpl_context. You can fill the variables inside theBaseController.__call__so that they are available everywhere.Another approach is to register
base_config.variable_providerinsideapp_cfg.pywhich must be a function that returns a dictionary of variables that will be available inside any template. Those variables will be overridden from the controller returned ones if there is a name collision, so it is a good way to provide defaults for controller returned variables.Otherwise in recent versions it is also possible to register the
before_renderhook systemwide usingbase_config.register_hookinsideapp_cfg.pythe callback can append and override any template parameter.