XF 2.0 Grabbing the Total Count of All Online Members, Guests, & Robots in Xenforo 2.0

[My apologies, I put this in the wrong forum yesterday]

I'm trying to simply get a count of all current users online.

I've dug through some of the widget templates to try to find the code block but they are all returning zero for me if I don't use them within the widget. I'm trying to add this to the PAGE_CONTAINER template to create a custom widget.

I've attempted using:
{$counts.total|number}
and
Code:
{{ phrase('online_now_x_members_y_guests_z',{
    'total': number($online.counts.total),
    'members': number($online.counts.members),
    'guests': number($online.counts.guests)})
}}

But again they're not returning any values but zero. I'm assuming there's some of ther chunk of code that needs to be in the PAGE_CONTAINER to allow those variables to be populated, but I can't figure it out. On the old Xenforo 1.X it worked magically for me in the sidebar_online_users template, but alas, not working for me now.

Can anyone point me in the right direction? Thanks a ton.
 
$online isn't passed to the PAGE_CONTAINER template, so you can't use it there.

It's passed to the widget_members_online template. See src/XF/Widget/MembersOnline.php.

You might want to consider creating your own code and widget, or modifying the existing widget.
 
Snog, thank you. Is it possible to grab the code for that widget or the online statistics one from it's own template and re-use portions of it to create this value in the PAGE_CONTAINER? Or even hide the rest with CSS, leaving only the value I'm looking for?
 
Snog, thank you. Is it possible to grab the code for that widget or the online statistics one from it's own template and re-use portions of it to create this value in the PAGE_CONTAINER? Or even hide the rest with CSS, leaving only the value I'm looking for?
There's no "easy" way to do that without creating an add-on to do it. (at least none I know of)

What exactly are you trying to do that the existing widget can't be used?
 
@Snog and anyone else reading, it took me a while to realize the solution.

I'm going to leave the "online statistics" widget intact, but edit the "Members Online" widget actual template. And then use it normally as a widget. Problem solved. You can simply copy and paste the values around such as {$counts.total|number}, placing it in the title, while removing the HTML for the body of the block.
 
Top Bottom