XF 1.5 Add Stats to Sidebar Visitor Panel – Best Practice?

Freelancer

Well-known member
I want to add third party add-on statistics, taken from the user's personal profile page sidebar "info block" to the forum home page "sidebar visitor panel" – using template modifications.

How to do it and what's the best practice (as "hooks" are depreciated)?

Thanks in advance.
 
Assuming the data is available to the template (you would need to check with the developer of the add-on which the stats relate to), just edit the template and add the relevant code, or include the template.

I wouldn't recommend creating an add-on just to have a template modification.
 
So you just recommend that I should copy the code from the other place directly into the sidebar visitor panel. I would have liked to have it as a template mod, because its more convenient to switch off the mod if the third party add-on is deactivated or uninstalled. Since I was looking at the hooks which are depreciated I am now a little bit lost on how to implement the syntax and where exactly.

Maybe just start with Resources and Media to be summarized under the default stats of the sidebar visitor panel.

I was coming from the hook insert (which is used for the user profile sidebar info block) but can not insert it into the visitor panel block because the template has the wrong markup (confirmed bug). Is there any other way to do it?

hook.webp
 
In the example of media and resources stats, they would get disabled automatically when the add-ons are disabled because the {$canViewResources} or {$canViewMedia} variables can't be true while the add-ons are disabled.

For the others, you can check if they are enabled using:

Code:
<xen:if is="{$xenAddOns.AddOnId}">
<!-- code -->
</xen:if>

Replace "AddOnId" with the add-on ID of the add-on, e.g. 'XenGallery'. This will only return true if the add-on is enabled.

So, all thing's considered, I still recommend just editing the template directly.
 
Okay, almost finished... only one thing does not seem to work...

On the member profile view page infoblock it works with:
Code:
<xen:if is="{$canViewWarnings}">
enclosure. However on the sidebar visitor panel it leads to not being rendered at all. As soon as I remove the enclosure it shows up. What am I missing?
 
That particular variable won't be available in the template. Though as it's a global permission it should be possible to check it in the template with something like:

Code:
<xen:if is="{$visitor.permissions.general.viewWarnings}">

Off the top of my head.
 
I am tracking. Guessed the variable was missing on forum home, but your code suggestion is not working, unfortunately. If you could provide me the correct string, then I'm actually complete. Will show screenshots when ready.
 
The $canViewWarnings variable is registered at the public function actionMember() for XenForo_ControllerPublic_Member class. To make it work on the sidebar, you must register it to the Index function of XenForo_ControllerPublic_Forum class. You can do so in one of those add ons that you are using. Extend it for the function and class that I mentioned above.

The code posted above has a type. It should be viewWarning, without s. Try it like this. It should work.

HTML:
<xen:if is="{$visitor.permissions.general.viewWarning}">
 
Awesome... I know that I have put you through hell, and I know that I have been one rough pecker. But from here on, you are all in my cool book. (y)

Here is the final result. To the left with text and to the right with (customized) UI.X Sidebar Stat Icons enabled. I managed to have everything conditional depending on if an add-on is present or not and if the visitor can actually view the stats or not plus having correct links to the according places, which is quite cool, because now one can login to forum home and directly jump to his postings or likes without having to go to his profile page first.

Thank you all!

sidebar_panel.webp

ps: I know the Icon solution to the right calls for a staggered column layout which I will do if I have the mood for it... :coffee:
 
Back
Top Bottom