On Sep 25, 9:51 am, Christopher Arndt <[EMAIL PROTECTED]> wrote:
> Matt Wilson schrieb:
>
> > I have a widget that draws a list of links at the top of every page.
> > I highlight certain links depending on the current page and depending
> > on some data in my database.
>
> > Right now, in every single controller method, I have to instantiate
> > and return this widget. It's tedious. Is there a better way to
> > always return this widget?
>
> http://docs.turbogears.org/1.0/Configuration#turbogears-app-cfg-confi...
>
> Look for 'tg.include_widgets'
>
> BTW: You shouldn't need to instantiate the widget for every request.
> Instantiate it once in the module where you define it and import it from
> there or put the dotted-path for it in tg.include_widgets.
Hi Chris, thanks for the link.
At first, It seemed like the code in turbogears.controllers.py just
iterates through those widgets and extracts all the relevant
javascript and CSS files and strings, but it didn't add the widget
itself to the template.
Then I saw how it does add the widget, but it changes the name in this
block:
for i in include_widgets_lst:
widget = tg_util.load_class(i)
if isclass(widget):
widget = widget()
include_widgets["tg_%s" % i.split(".")[-1]] = widget
So, my original widget was called hw, but in my template, I needed to
refer to it as tg_hw.
I'm posting this here for future reference.
Matt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---