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

Need help with TemplateHook - can't get $user to work correctly

Discussion in 'XenForo Development Discussions' started by lasertits, Oct 30, 2011.

  1. lasertits

    lasertits Active Member

    Here's what I have going on. I've got a plague_message_bar template, containing:
    Code:
    <xen:require css="plague_message_bar.css" />
    <div class="plagueMessageBarContainer">
        <xen:hook name="group_tags" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">
            <div class="plagueMessageBarUsername">
                <xen:username user="$user" itemprop="name" rich="true" />
            </div>
        </xen:hook>
    </div>
    This is added before the message_notices hook with the following listener:

    PHP:
                case 'message_notices';
                {
                    
    $mergedParams array_merge($template->getParams(), $hookParams);
                    
    $contents $template->create('plague_message_bar'$mergedParams) . $contents;
                    break;
                }
    But no dice (error below). I also tried this:

    PHP:
                case 'message_notices';
                {
                    
    $contents $template->create('plague_message_bar'$template->getParams()) . $contents;
                    break;
                } 
    And still no avail.

    What I'm basically trying to do, is pull the username of the message author and slap it in my custom plague_message_bar template, rather than having it inside message_user_info.

    The group_tags hook is for another listener which adds content AFTER (or to the right of) the username, this will be my next area to tackle once I can get the usernames going, also I should note the group_tags listener is disabled so it shouldn't be affecting my attempts to get the usernames to work.

    Here's the error I get on thread / conversation views when it loads my plague_message_bar template:

    Code:
    Template Errors: plague_message_bar
    
        Argument 1 passed to XenForo_Template_Helper_Core::helperUserNameHtml() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 1488
        Argument 1 passed to XenForo_Template_Helper_Core::helperRichUserName() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 878
        Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, null given, called in /*removed*/library/XenForo/Template/Helper/Core.php on line 1500 and defined in /*removed*/library/XenForo/Template/Helper/Core.php, line 1389
    
    Template Errors: plague_message_bar
    
        Argument 1 passed to XenForo_Template_Helper_Core::helperUserNameHtml() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 1488
        Argument 1 passed to XenForo_Template_Helper_Core::helperRichUserName() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 878
        Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, null given, called in /*removed*/library/XenForo/Template/Helper/Core.php on line 1500 and defined in /*removed*/library/XenForo/Template/Helper/Core.php, line 1389
    
    Template Errors: plague_message_bar
    
        Argument 1 passed to XenForo_Template_Helper_Core::helperUserNameHtml() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 1488
        Argument 1 passed to XenForo_Template_Helper_Core::helperRichUserName() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 878
        Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, null given, called in /*removed*/library/XenForo/Template/Helper/Core.php on line 1500 and defined in /*removed*/library/XenForo/Template/Helper/Core.php, line 1389
    
    I'm pretty stumped. Where's my mistake(s) in all this? :confused:

    Thanks.
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    Have you tried this?

    PHP:
    case 'message_notices';
    {
        
    $mergedParams array_merge($template->getParams(), $hookParams);
        
    $myTemplate $template->create('plague_message_bar'$mergedParams);
        
    $rendered $myTemplate->render();
        
    $contents =  . $rendered;
        break;
    }
     
  3. lasertits

    lasertits Active Member

    Hi Fuhrmann, thanks for the suggestion. Unfortunately it gives me the same set of array errors.

    I tried both $contents = $rendered and $contents = $contents . $rendered, as $contents = . $rendered; gave me a syntax error.

    Code:
    Template Errors: plague_message_bar
        Argument 1 passed to XenForo_Template_Helper_Core::helperUserNameHtml() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 1488
    
        Argument 1 passed to XenForo_Template_Helper_Core::helperRichUserName() must be an array, null given in /*removed*/library/XenForo/Template/Helper/Core.php, line 878
    
        Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, null given, called in /*removed*/library/XenForo/Template/Helper/Core.php on line 1500 and defined in /*removed*/library/XenForo/Template/Helper/Core.php, line 1389h
    
     
  4. Fuhrmann

    Fuhrmann Well-Known Member

    Try using this in your template:

    Code:
    <xen:username user="$message" itemprop="name" rich="true" />
    I have done exactly what you are trying to do, and it works for me.
     
  5. lasertits

    lasertits Active Member

    Bingo! Can't believe I didn't think to try $message instead of $user after various different listener attempts. Thanks so much!
     
    Fuhrmann likes this.
  6. Fuhrmann

    Fuhrmann Well-Known Member

    Glad to know!

    As Kier said here:

    Code:
    <xen:include template="message_user_info">
        <xen:map from="$message" to="$user" />
    </xen:include>
    So you have to use $message.
     
    infis likes this.

Share This Page