Jump to the post that solved this thread.
Solved: 1 Year, 11 Months ago Dynamic PM Alert Class?
#1
Solved: 1 Year, 11 Months ago
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.
Reply
#2
Solved: 1 Year, 11 Months ago
<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 man, what's up?
Reply
#3
Solved: 1 Year, 11 Months ago
(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.
Reply
#4
Solved: 1 Year, 11 Months ago
(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
Hey man, what's up?
Reply
#5
Solved: 1 Year, 11 Months ago
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>
Reply
#6
Solved: 1 Year, 11 Months ago
(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.
Hey man, what's up?
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)