View Full Version : notifications_total in FORUMHOME
Cadellin
04-11-2012, 08:10 PM
I'm trying to display $notifications_total in the FORUMHOME template ({vb:raw notifications_total} but without success whereas the same variable works fine elsewhere.
I assume my issue is that $notifications_total isn't a global variable in which case what can I do?
Thanks for any assistance.
Boofo
04-11-2012, 08:15 PM
Try:
{vb:raw notifications_total}
Cadellin
04-11-2012, 08:33 PM
Thanks Boofo but I've tried that. Typo in the top post.
Boofo
04-11-2012, 08:50 PM
The it must not be available on the forumhome. You might need to do a query for it.
Cadellin
04-11-2012, 09:23 PM
I've come up with the below which works on FORUMHOME and SHOWTHREAD.
I want to use this in a lot of templates so would it be better to make it a global variable (if that's possible) or should I just create a long list of preRegisters?
$currentuserid = $vbulletin->userinfo[userid];
$query = "SELECT * FROM prefix_user WHERE userid = $currentuserid";
$result = $db->query($query);
while($row = $db->fetch_array($result)) {
$a = $row['friendreqcount'];
$b = $row['vmunreadcount'];
$c = $row['socgroupinvitecount'];
$d = $row['socgroupreqcount'];
$e = $row['pcunreadcount'];
$f = $row['vbseo_likes_unread'];
$h = $row['pmunread'];
}
$title_note_count = $a + $b + $c + $d + $e + $f + $h;
vB_Template::preRegister('FORUMHOME',array('title_ note_count' => $title_note_count));
vB_Template::preRegister('SHOWTHREAD',array('title _note_count' => $title_note_count));
Thanks for your help!
Boofo
04-11-2012, 09:56 PM
Where are you trying to use this?
Cadellin
04-12-2012, 07:34 AM
I'm trying to get the total number of notifications into the page title in a similar way to Twitter or Facebook. E.g. "(4) vBulletin.org Forum".
Boofo
04-12-2012, 07:51 AM
I don't use Twitter or Facebook so I have no idea how they do things. Where are you wanting this to show up exactly?
Cadellin
04-12-2012, 08:20 AM
Sorry I'll try to explain better.
I want to add the total number of notifications to HTML page title. Like this:
So in the template something like this (variables are from memory):
<title>({vb:raw notifications_total}) {vb:raw bboptions:title}</title>The result of which would be something like this:
https://vborg.vbsupport.ru/attachment.php?attachmentid=137711&stc=1&d=1334222215
Thanks
I don't think you need to do a query because the global $notifications_total should contain the total (assuming it's been calculated at the point you're trying to use it, of course), but it has to be registered to the template(s) where you want to use it. If you create a plugin using hook process_templates_complete you should be able to do preRegisters there. (process_templates_complete was just added a couple versions ago so it's possible you don't have it if you're not up to date).
You would have to register it to each template as I don't think there's any way to globally register to all templates. But there is a number of globals that *are* registered automatically in each template, so you could piggy back on one of those. For instance, $vbulletin->userinfo is registered as bbuserinfo, so in your plugin you could set $vbulletin->userinfo['notifications_total'] = $notifications_total then use {vb:raw bbuserinfo.notifications_total} in each template. (Probably some people will tell you that you shouldn't really do it this way, but I don't see a problem with it).
Boofo
04-12-2012, 12:12 PM
It seems to already be a legacy output global in the navbar.php. Maybe try using this in the navbar?
$GLOBALS['notifications_total']
Cadellin
04-12-2012, 05:48 PM
All working now! I ended up using the code below although your suggestion also worked Boofo but the below feels more elegant and certainly shorter.
$vbulletin->userinfo['notifications_total'] = $notifications_total; process_templates_complete hook.
Thanks for the global variable trick kh99 - works perfectly! Thanks as well Bofo
/Solved.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.