How do I know if there is an alert to initiate an action ?
I guess I have got a wrong code here
/* Growl Notifications Angular */
if (!empty($txt['notify']))
echo '
<growl-notification class="fading">
You have active notifications
</growl-notification>';
Or, should I have to replace $txt with $context['notification_set'] ?
Txt only contains strings, so I wouldn't check if it's empty.
What should I check to see whether there is a notification or not ?
Do you mean the mentions? This holds the number of mentions (if you compare it > 0, and true, then there is a mention):
$context['user']['mentions']
So, I would need to check 2. If there is like , if there is mention. Then I can display notification.
You check is there is a "mention" (i.e. notification, yeah, same name for two things), a mention includes likes, @ mentions, and some other stuff.
Yes. Is it possible that I can have the code to check both ? I am not good in php.
Some other stuff includes what all ? At the moment, I am concentrating on presence of like and @ mention
PS: I mean, compare if > 0 inclusive
Use what CrimeS suggested. It is for both.
php doubt. Something wrong with this code ?
/* Popup alert notification using Growl Notifications */
function growl_based_notification()
{
global $context;
if (!empty($context['user']['mentions']))
// Say they have unread alerts.
$html = '<body ng-app="af_notify" ng-controller="growlCtrl">
<growl-notifications></growl-notifications>
<growl-notification>
Psst ! You have unread notifications
</growl-notification>
</body>';
return $html;
}
Yes and no.
If you mean "is the ElkArte way?" then the answer is: yes there is something wrong.
If you mean "is the code syntactically correct?" Then the answer is: no, nothing wrong.
Sorry ?
I asked because I did everything as per this Plunker code but getting no alert despite having an active mention
http://plnkr.co/edit/ZZHW0JKumXfdFgjTjVJz?p=preview
Another way to say what I wrote it: the snippet of code you posted
as is doesn't work in ElkArte, but is valid PHP code.
So, depending on what you are doing it may or may not work.
Guessing from your posts your question is: does that code work in ElkArte?
And then the answer is: no, because "return" is not "echo", and returning the HTML doesn't send it to the template, for that you need "echo", because that's the way ElkArte works.
Then there is the second problem: when $context['user']['mentions'] is 0, $html is not initialized, so ElkArte will throw an error.
This ?
/* Popup alert notification using Growl Notifications */
function growl_notification()
{
global $context;
if (!empty($context['user']['mentions']))
// Say they have unread alerts.
echo '
<body ng-app="af_notify" ng-controller="growlCtrl">
<growl-notifications></growl-notifications>
<growl-notification>
Psst ! You have unread notifications
</growl-notification>
</body>';
}
Works fine if I use only echo part. ie, remove if ( context ) in above code
(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3042;image)
$context['user']['mentions'] > 0
@Wizard have you seen this addon http://www.elkarte.net/community/index.php?topic=2795.0 ?
Yes. This is mention alerts. It cannot be configured. It will show you an alert window and take your attention to new like or @ mention or whatever it is. Besides, I am using AngularJS
PS : The display is not yet available
/* Popup alert notification using Growl Notifications */
function growl_based_notification()
{
global $context;
if (!empty($context['user']['mentions']) > 0)
// Say they have unread alerts.
echo '
<body ng-app="af_notify" ng-controller="growlCtrl">
<growl-notifications>
<growl-notification>
Psst ! You have unread notifications
</growl-notification>
</growl-notifications>
</body>';
}
1st: <body> is a tag with a specific meaning, you should not use it in the middle of a page "at random".
2nd: empty returns true or false, there is no reason to do a !empty($something) > 0
Try with:
global $user_info;
if (!empty($user_info['mentions']))
Sorry, I didn't see the !empty check :)
Using this, but no Alerts display
/* Popup alert notification using Growl Notifications */
function growl_based_notification()
{
global $user_info;
if (!empty($user_info['mentions']))
// Say they have unread alerts.
echo "<pre>" . print_r($user_info, 1) . "<pre>\n";
echo '
<html ng-app="af_notify" ng-controller="growlCtrl">
<growl-notifications>
<growl-notification>
Psst ! You have unread notifications
</growl-notification>
</growl-notifications>
</html>';
}
growl_based_notification();
But when I add
echo "<pre>" . print_r($user_info, 1) . "<pre>\n";
it shows the alert window. But does not vanish even if I logout
(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3046;image)
I have added a dismiss button
But still no luck with the condition :(
(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3048;image)
Where are you calling that function from?
I am simply copy pasting this whole code on index.template.php
You are declaring a function.
If you declare a function you have to call it in order to let it run.
So, where are you calling this function in index.template.php?
Yes, just after declaring it.
@emanuele , anything you can do ?
Then you are running it at the wrong time.
You have to call that function in a particular point of the template, not when the file is "included".
Most likely you have to call that function at the beginning of template_body_above or somewhere like that, but by all means
inside a template_* function or through the template layers mechanism.