Notification Editor for Elgg
, (*1)
Features
- Editable HTML notification templates built with Mustache
- Flexible use of object and variables in templates
- An option to send intstant notification with custom templates
, (*2)
Subscription Notifications
The plugin will automatically hijack notifications for all registered notifications events (events that
send out subscription notifications). The plugin will first try to locate a view that corresponds to
the subject, summary and body of the notification, and use the template view, if it's found.
Administrators have the ability to edit the templates, in which case a new template object is
created and stored in the database., (*3)
Notification views are stored in:
/views/default/notifications/$action/$object_type/$object_subtype/$part.$language.html
, where
$action
is an action triggering the notification event,
$object_type
is object
, group
, user
, site
, annotation
or relationship
$object_subtype
is an entity subtype, or annotation name, or relationship name
$part
is either subject
, summary
or body
$language
is the language of the recipient, (*4)
Custom (Instant) Notifications
For this to work, your delivery method handlers need to trigger 'format','notification'
hook and pass the
notification object as return. For email delivery method, enable notifications_html_handler plugin., (*5)
// enable templates for notifier
elgg_register_plugin_hook_handler('send', 'notification:notifier', 'notifier_notification_send');
function notifier_notification_send($hook, $type, $result, $params) {
$notification = $params['notification'];
$notification = elgg_trigger_plugin_hook('format', 'notification', $params, $notification);
// continue with logic
}
You can send instant notifications using templates by passing a template name with the notification parameters:, (*6)
notify_user($to, $from, '', '', array(
'template' => 'my_template',
'my_param' => $param,
));
You can then edit your templates, and reference your params as so:, (*7)
// in notifications/my_template/body.en.html
This is my template with {{params.my_param}}!
To make templates editable by admin, register them:, (*8)
elgg_register_plugin_hook_handler('get_templates', 'notifications', function($h, $t, $r) {
$r[] = 'my_template';
return $r;
}
Below you can see how to send a notification using a custom template., (*9)
Let's say we want to notify a user that their account has been created:, (*10)
notify_user($recipient->guid, $site->guid, '', '', array(
'template' => 'useradd',
'actor' => elgg_get_logged_in_user_entity(),
'password' => '123456789',
));
// in /views/default/notifications/useradd/body.en.html
Dear {{recipient.name}},
{{#actor}}
{{actor.name}} has created an account for you at <a href="{{site.getURL}}">{{site.name}}</a>.
{{/actor}}
{{^actor}}
A use raccount has been created for you at <a href="{{site.getURL}}">{{site.name}}</a>.
{{/actor}}
Your login credentials are as follows:
Username: {{recipient.username}}
Password: {{params.password}}
Once you have logged in, we highly recommend that you change your password.
You can do so in your <a href="{{site.getURL}}settings/user/{{recipient.username}}">account settings</a>.
<a href="{{site.getURL}}login" class="elgg-button">Login</a>
Properties
Properties available in templates:, (*11)
See mustache reference for information on ternaries and loops, (*12)
Available in all notifications
**{{sender.name}}** |
Name of the sender |
**{{sender.getURL}}** |
URL of the sender's profile |
**{{sender.XXX}}** |
Any metadata or method attached to the sender object (e.g. {{sender.language}}) |
**{{recipient.name}}** |
Name of the recipient |
**{{recipient.getURL}}** |
URL of the recipients's profile |
**{{recipient.XXX}}** |
Any metadata or method attached to the recipient object (e.g. {{recipient.first_name}}) |
**{{language}}** |
Language of the recipient |
**{{site.name}}** |
Name of the site |
**{{site.getURL}}** |
URL of the site (with the trailing slash) |
**{{params.XXX}}** |
Additional params passed to the notification object. The actual available values depend on the notification |
Available in subscription notifications
**{{action}}** |
Action name that triggered the subscription notification event |
**{{actor.name}}** |
Name of the actor (a user performing an action) |
**{{actor.getURL}}** |
URL of the actor's profile |
**{{actor.XXX}}** |
Any metadata or method attached to the actor object (e.g. {{actor.language}}) |
**{{object.XXX}}** |
Depending on the event, an object is either an entity, or an annotation, or a relationship. Available properties may vary depending on that. |
**{{target.XXX}}** |
Target of the event: For events that involve Elgg entities, the target is the container entity, e.g. if object is a blog, the target is either a user or group For events that involve annotations, the target is an entity that that annotation is made on For events that involve relationships, the target is an object with subject and object properties, where subject represents the subject of the relationship and object represents the object of the relationship |