• 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

lasertits

Active member
#1
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.
 

Fuhrmann

Well-known member
#2
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;
}
 

lasertits

Active member
#3
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
 

Fuhrmann

Well-known member
#4
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.
 

lasertits

Active member
#5
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.
Bingo! Can't believe I didn't think to try $message instead of $user after various different listener attempts. Thanks so much!
 

Fuhrmann

Well-known member
#6
Bingo! Can't believe I didn't think to try $message instead of $user after various different listener attempts. Thanks so much!
Glad to know!

As Kier said here:

Kier said:
$user in the message_user_info template is a mapped variable. If you look at the include line in the messagetemplate where message_user_info is called, you can see the $user variable being created.
Code:
<xen:include template="message_user_info">
    <xen:map from="$message" to="$user" />
</xen:include>
So you have to use $message.