delagate to catch submodule events

waltaskew edited this page Sep 13, 2010 · 3 revisions

if you use a template which calls a module (I will refer this as submodule), rather than the page itself
(see example below) and you try to use events on the submodule, the
events will go to the page:event function. if you want to handle the
events in the submodule you should delegate the event to the module.
for example:

i have a template which call the page module (normal usage), and
another module which i use on all my pages:



[[[page:body()]]]
[[[another_module:render()]]]

and the another_module have a button in it, which i want to work on
all the pages that use it.
so if i just add on another_module:render/0 the button:

#button{id=btn, text=“Do Domthing”, postback=do_something}

the callback to the event function will be done by nitrogen on the
master web page module (‘page’) and not on the another_module:event
function.
if you want to set it to be sent to the another_module, use:

#button{id=btn, text=“Do Domthing”, postback=do_something}

wf:wire(btn, #event{type=click, delegate=?MODULE, postback=
do_something}),