A plugin to display notifications
To install Usernotifications, follow these steps:
- Download & unzip the file and place the
usernotifications
directory into yourcraft/plugins
directory - -OR- do a
git clone https://github.com/Anubarak/usernotifications.git
directly into yourcraft/plugins
folder. You can then update it withgit pull
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
usernotifications
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
Usernotifications works on Craft 2.4.x and Craft 2.5.x.
During the install process a new section usernotifications
is created with 5 test elements in it. Each entry type can have it's own template so you can create different entry types for different purposes which give you the freedom to define
which user is able to see which message in your template like you are used to.
For example when you create a new entry type onlyAdminsSeeMee
and the file usernotifications/templates/entries/entrytypes/onlyAdminsSeeMee
and include
{% if currentUser.isAdmin() %}
hey admin, here is a new message {{ entry.content }}
{% endif %}
in the template only admins will see it and no one else.
This makes it really flexible. You can add relation fields to your entry in order to have access to other entries as well in your template. For example if you would like to notify others about a new topic you'll relate this new topic to your notification and can do
{% set newTopic = entry.relationField.first() %}
hey dude :D want to check out {{ newTopic.title }}?
just click here <a href="{{ newTopic.getUrl()"></a>
To render notifications you have to do
{% set notifications = craft.usernotifications.getAllNotificationsForUser() %}
{{ notifications|raw }}
Brought to you by Robin Schambach