Add "Your Trophies" Button to Account Menu

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 $hookParams, XenForo_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 :)
 
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.
 
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):

Rich (BB 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);
			}
		}
	}
 
Top Bottom