MyBB Community Forums

Full Version: Dynamic PM Alert Class?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

As you can see from the screenshot, I've managed to get a user's number of alerts and PMs displayed on my forum.

[Image: nGmUVWQ.png]

For the alerts, I'm using the MyAlerts plugin; for the messages, just using the default system.

What I would like to do is have dynamic styles depending on if there are alerts/PMs.

For instance: If there are 0 alerts/PMs, the purple background in the screenshot should be grey. Then, if the alerts/PMs value is > 0, it will show a different color.

I'm capable of making the CSS classes, I'm just not quite sure how to have the values determine which class to utilize.
<span class="alerts trigger{$mybb->user['unreadAlerts']}"> ** use this for alerts

<span class="pm trigger{$mybb->user['pms_unread']}"> Use this for pm

then just do something like


.alerts {
background:#4c00ce;
}

.pm {
background#4c00ce;
}

.trigger0 {
display:none !Important;
}


just experiment and have fun,

please let me know if this works or not, so I can help you.

Man, i just realized, the css stack structure is wrong, you need to have the trigger class above alerts and pm to drop the !Important
(2020-10-28, 02:07 AM)Michael2014 Wrote: [ -> ]<span class="alerts trigger{$mybb->user['unreadAlerts']}"> ** use this for alerts

<span class="pm trigger{$mybb->user['pms_unread']}"> Use this for pm

then just do something like


.alerts {
background:#4c00ce;
}

.pm {
background#4c00ce;
}

.trigger0 {
display:none !Important;
}


just experiment and have fun,

please let me know if this works or not, so I can help you.

Man, i just realized, the css stack structure is wrong, you need to have the trigger class above alerts and pm to drop the !Important

Hey Michael,

Thank you so much for the reply - I'll try this out soon and post back with the results (looks very promising, you're a genius!)

Thanks again ~

Works fantastic! Appreciate the help. Something to note though: oddly enough, I needed the class structure the way you had it first in order for this to work. Meaning, the trigger0 had to be on the bottom.
(2020-10-28, 02:05 PM)tomjay78 Wrote: [ -> ]
(2020-10-28, 02:07 AM)Michael2014 Wrote: [ -> ]<span class="alerts trigger{$mybb->user['unreadAlerts']}"> ** use this for alerts

<span class="pm trigger{$mybb->user['pms_unread']}"> Use this for pm

then just do something like


.alerts {
background:#4c00ce;
}

.pm {
background#4c00ce;
}

.trigger0 {
display:none !Important;
}


just experiment and have fun,

please let me know if this works or not, so I can help you.

Man, i just realized, the css stack structure is wrong, you need to have the trigger class above alerts and pm to drop the !Important

Hey Michael,

Thank you so much for the reply - I'll try this out soon and post back with the results (looks very promising, you're a genius!)

Thanks again ~

Works fantastic! Appreciate the help. Something to note though: oddly enough, I needed the class structure the way you had it first in order for this to work. Meaning, the trigger0 had to be on the bottom.

Ah, I guess I was wrong, so you correct then, thanks for correcting me on the correct css structure, looks good, glad it helped! Smile
Just figured out another (possibly cleaner) way of doing this in case anyone is interested.

First install the template conditionals plugin, then just use something like this:

<if $mybb->user['unreadAlerts'] == 0 then><div class="notif-not-found">{$mybb->user['unreadAlerts']}</div><else><div class="notif-found">{$mybb->user['unreadAlerts']}</div></if>
(2020-10-29, 04:52 AM)tomjay78 Wrote: [ -> ]Just figured out another (possibly cleaner) way of doing this in case anyone is interested.

First install the template conditionals plugin, then just use something like this:

<if $mybb->user['unreadAlerts'] == 0 then><div class="notif-not-found">{$mybb->user['unreadAlerts']}</div><else><div class="notif-found">{$mybb->user['unreadAlerts']}</div></if>

I love template conditionals, I use it too. But downloading a plugin, vs. standard mybb core is never a "better" solution" Core is always better.