Lee McFadden schrieb:
> The above issue is one of the reasons I make sure none of my Widgets
> require JS that can't be added to the template by hand - I instantiate
> all my widgets outside of controllers and add them to the default
> providers so they don't have to be passed by a controller for them to
> be used in the view.
You should use 'tg_include_widgets' and then you could use JS/CSS with widgets
again too.
I have this function in a 'widgets.base' module of my apps:
def register_sitewidgets(widgets, pkg_name):
"""Register widgets to be included on every page.
'widgets' is a list of widget instance names.
Order of the widget names is important for proper inclusion
of JavaScript and CSS.
The named widget instances have to be instantiated in
some of your modules.
'pkg_name' is the name of your Python module/package, in which
the widget instances are defined.
"""
# first get widgets listed in the config files
include_widgets = config.get('tg.include_widgets', [])
# then append given list of widgets
for widget in widgets:
include_widgets.append('%s.%s' % (pkg_name, widget))
config.update({'global': {'tg.include_widgets': include_widgets}})
and in my controllers.py I have:
# register site-wide widgets to be included on every page
register_sitewidgets(sitewidgets, 'myapp.widgets')
where I have defined (or imported) the widgets in module 'maypp.widgets'.
Both both solutions, yours and mine, are only useful for widgets that appear on
every page, aren't they? Or do you have special logic in your variable
providers to include only specific widgets on a per-request basis?
Chris
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---