On Dec 12, 2007 7:25 PM, Tim Lesher <[EMAIL PROTECTED]> wrote: > > > I don't think this question has anything to do with forms--I think > he's asking "how can I change text in my master.kid to something that > comes from my db?" >
If this really is the question, there is a much more simple solution than creating the same query in every controller: the TurboGears variable provider. In most of my projects I usually have a module called util that extends the standard variable providers in TG. If you only have one thing that you need site wide, you can just as easily create this in your controllers.py. The code required is simple, and I'll use your example; getting header content from your database. We'll assume that you already have the model set up and it's called PageElement, and it has an id, a name and a content field. We'll also assume that you're using SA 0.3, although the method below could be used for anything you like, you don't even have to interact with the database. in controllers.py make sure you have the following code, replacing `projectname` with the module name of your project: [code] from turbogears import view from projectname import model def get_header_content(self): return model.PageElement.get_by(name="header") def append_providers(vars): vars["get_header_content"] = get_header_content view.variable_providers.append(append_providers) [/code] Now, you could have used a lambda to do that, but for completeness I used a function to show that your functions _can_ be as complex as needed. You can now use `${tg.get_header_content()}` in your templates at any point. In some cases I create request local caching for things that may need to be used in multiple places in the same content if you're querying the database using cherrypy.request to store some data. I hope that helps ease development of features like this, I know it was a huge relief for me when I found I could use this method. -- Lee McFadden blog: http://www.splee.co.uk work: http://fireflisystems.com skype: fireflisystems --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---