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

Add "Your Trophies" Button to Account Menu

Discussion in 'XenForo Development Discussions' started by Teapot, Jan 11, 2013.

  1. Teapot

    Teapot Well-Known Member

    Okay, so, I'm trying to add a "your trophies" button to the account menu that links to members/<visitor's username>/trophies. I've got all the code needed to make the button appear, but I'm having trouble figuring out the syntax for {xen:link}.

    What I have at the moment is this:
    teapot_navigation_mytrophies
    HTML:
    <li>
        <a href="{xen:link 'members/trophies', $visitor}">
            {xen:phrase your_trophies} ({xen:number $visitor.trophy_points})
        </a>
    </li>
    library/Teapot/MiscTrophies/UserMenuTrophies.php
    PHP:
    class Teapot_MiscTrophies_UserMenuTrophies
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if (
    $hookName == 'navigation_visitor_tab_links2')
            {
                
    $contents .= $template->create('teapot_navigation_mytrophies');
            }
        }
    }

    If I click the link currently, it tries to direct me to members/trophies - which of course leads to an error. I've pretty much copied the link code verbatim from here. As an aside, the {xen:number} doesn't work either, probably for the same reason.

    Thanks for your time :)
     
    Digital Doctor likes this.
  2. James

    James Well-Known Member

    You've created a new template and not exposed the $visitor variable to your new template, so it doesn't recognise it.

    To test, use a dump to see if your $visitor variable works: {xen:helper dump, $visitor} - it will probably return NULL.

    You'll need to pass some viewParams along with your new template.
     
    Chris D likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    You're not passing any parameters to your template.

    This makes all of the parent template parameters available to your template. (I've added the code in red):

    Code:
    	class Teapot_MiscTrophies_UserMenuTrophies
    	{
    		public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    		{
    			if ($hookName == 'navigation_visitor_tab_links2')
    			{
    				$params = $template->getParams();
    				$contents .= $template->create('teapot_navigation_mytrophies', $params);
    			}
    		}
    	}
     
    Teapot likes this.
  4. Teapot

    Teapot Well-Known Member

    Thanks a lot, that worked :)
     
    Chris D likes this.

Share This Page