Go to page content


Signal and slot mechanism for use in templates.

mod_signal allows template developers to create pages with highly interactive behaviour. It allows one to emit so called signals. Signals are asynchronous events with attributes. Other pages can connect to the signature of a signal. When that signal is fired, the specified action is triggered. This makes it possible to create interactive pages without writing a line of erlang code.


A signal is an erlang tuple which can be emitted either by erlang code:

mod_signal:emit({example, [{test, "a"}, {session, 123}]}, Context)

or by using the emit action in a template.

{% button action={emit signal={example test="a" session=123}} %}

Signals themselves don't do much. The fun part is connecting other stuff to signals. When a signal is emitted mod_signal examines if there is something which is interested in this particular signal. It could be that there are actions connected to signals of type 'example'. When such a signal is emitted the registered action is performed. This can be done with the connect action.

{% wire action={connect signal={example session=123} action={growl text="example"}} %}

The action above will trigger the grow action when a signal of type example and with property {session, 123} is emitted. It is possible to make multiple matches on the property of a signal.


The module has three actions which can be used to connect and disconnect to signals, and an action to emit signals.


{connect signal={signal_type prop1=value} action={...}}


signal - The pattern of a signal to which you want to connect to

action - The action you want to perform when a signal matching the pattern is emitted.

name - The name of the connection. Giving a connection a name makes it possible to disconnect it at a later stage


{emit signal={signal_type prop1=123}}


signal - The signal you want to emit. When there is a slot which matches the pattern of the emitted signal, it will receive the signal. Note that it is possible that multiple slots match this signal. 


{disconnect name="my-signal"}


name - Disconnect from the named slot. 



Makes it possible to access the emitted signal in a template. 

m.signal[signal].type - The type of the emitted signal

m.signal[signal].props - The property list of the emitted signal

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.