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

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

Discussion in 'Resolved Bug Reports' started by Jaxel, Mar 1, 2011.

  1. Jaxel

    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:
    Even though I can create an instance for visitor, it then can't be passed into the <xen:avatar> helper.
     
  2. Shadab

    Shadab Well-Known Member


    Code:
    XenForo_Visitor::getInstance()
    returns an object of type: XenForo_Visitor.
    To convert it into a plain array, use:
    Code:
    XenForo_Visitor::getInstance()->toArray()
     
  3. Jaxel

    Jaxel Well-Known Member

    Thank you... that work around works... that being said, this bug should still be looked at.
     
  4. Kier

    Kier XenForo Developer Staff Member

    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());
     
    shenmuee likes this.

Share This Page