1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Styling and Customization Questions' started by Freelancer, Dec 16, 2015.

  1. Freelancer

    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.
  2. Brogan

    Brogan XenForo Moderator Staff Member

    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.
  3. Freelancer

    Freelancer Well-Known Member

    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?

  4. Brogan

    Brogan XenForo Moderator Staff Member

  5. Chris D

    Chris D XenForo Developer Staff Member

    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:

    <xen:if is="{$xenAddOns.AddOnId}">
    <!-- code -->
    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.
  6. Freelancer

    Freelancer Well-Known Member

    Okay, thank you both. I will try to edit the template directly without template mod and make all things conditional. Let's see how far I get...
  7. Freelancer

    Freelancer Well-Known Member

    Okay, almost finished... only one thing does not seem to work...

    On the member profile view page infoblock it works with:
    <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?
  8. Chris D

    Chris D XenForo Developer Staff Member

    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:

    <xen:if is="{$visitor.permissions.general.viewWarnings}">
    Off the top of my head.
  9. Freelancer

    Freelancer Well-Known Member

    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.
  10. wang

    wang Well-Known Member

    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.

    <xen:if is="{$visitor.permissions.general.viewWarning}">
    Freelancer and Chris D like this.
  11. Freelancer

    Freelancer Well-Known Member

    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!


    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:
    wang likes this.

Share This Page