Not a bug  Templates applied in hooks do not have access to $visitor...

Jaxel

Well-known member
Self explanatory... a template that is called in through a hook does not have access to $visitor.

I have tried to bypass this issue with the following:
Code:
$rsvpsModel = new EWRatendo_Model_RSVPs;

$params['visitor'] = XenForo_Visitor::getInstance();
$params['rsvps'] = $rsvpsModel->getRSVPsByEvent($params['event']);

$contents .= $template->create('EWRatendo_EventsView', $params)->render();

However, I then get the following error:
Argument 1 passed to XenForo_Template_Helper_Core::avatarHtml() must be an array, object given, called in /home/eightway/public_html/library/XenForo/Template/Abstract.php(243) : eval()'d code on line 126 and defined in /home/eightway/public_html/library/XenForo/Template/Helper/Core.php, line 1403
Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, object given, called in /home/eightway/public_html/library/XenForo/Template/Helper/Core.php on line 1431 and defined in /home/eightway/public_html/library/XenForo/Template/Helper/Core.php, line 1264

Even though I can create an instance for visitor, it then can't be passed into the <xen:avatar> helper.
 
Argument 1 passed to XenForo_Template_Helper_Core::avatarHtml() must be an array, object given,


Code:
XenForo_Visitor::getInstance()
returns an object of type: XenForo_Visitor.
To convert it into a plain array, use:
Code:
XenForo_Visitor::getInstance()->toArray()
 
I updated the event docs a few days ago because I've seen several people make this same mistake.

$params in the template_hook callback actually refers to template hook parameters, not the parameters passed to the template. See the editor template for an example of a template hook that passes parameters.

However, if you want your newly created template to have access to the same parameters as the template in which the hook exists, you need to use the following code:

PHP:
$contents .= $template->create(
    'EWRatendo_EventsView',
    $template->getParams());
 
Top Bottom