class BlockHeader(widgets.Widget):
template = """
<div>Page title: ${dbf(page_id).title}</div>
"""
params = [ 'page_id', 'dbf' ]
and in the controller:
w_header = BlockHeader( page_id=1, dbf=databaseFunction )
My question is whether I could instead add a custom helper function to
the widget class definition and somehow have the template be able to
call this function. At the moment it uses eval to conduct some jiggery
pokery around the name ...
If I add a method to the widget the template does not have access to it.
Should I try to add a property to the widgets template object? Is there
someway to access the widgets methods from within the template object?
Override the update_params method in the widget and add the function to the
params dictionary. This will give the template access to the function.
def foo():
return "Hello, World!"
class MyWidget(widgets.Widget):
template = """
<div xmlns:py="http://purl.org/kid/ns#" id="mywidget">
<p py:content="foo()" />
</div>"""
def update_params(self, params)
super(MyWidget, self).update_params(params)
params['foo'] = foo
HTH, Chris
It did, thanks. Works like a charm!
Iain