Jason Chu wrote:
> On Wed, 2 Aug 2006 02:09:20 +0200
> Alberto Valverde <[EMAIL PROTECTED]> wrote:
>
> > We can still keep the good 'ol variable_providers untouched for
> > backwards compatibility.
>
> I like variable_providers, it lets me specify things that are available
> throughout the entire application, instead of on a
> controller-by-controller basis (I assume you're not going to walk the
> controller tree up just to see what variables to apply).
>
> If we got rid of variable_providers entirely I'd be annoyed that
> turbogears can stuff things into the global kid namespace but I can't
> (the tg variable).

You could do that in a more elegant way:

1) By adding your method to the base Controller class before creating
an instance of it:

from turbogears import Controller

def my_global_provider(self):
     return dict(#stuff that into every template)

Controller.__variables__ = my_global_provider

class BlogController(Controller):
       ....

2) By subclassing the Controller class and using that new class as your
controller

class ApplicationController(Controller):
     def __variables__(self):
        return dict(stuff that into every controller)

This solution allows you to keep tg uncluttered by your stuffs and at
the same time you can stuff anything into *every* templates or just
*some* templates in the way you want, this means you can use custom
namespace or object to group things (and not just tg) or just plain
methods or widget instances. ;-)

Ciao
Michele


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to