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

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.
 
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;
}
 
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
 
Try using this in your template:

Rich (BB code):
<xen:username user="$message" itemprop="name" rich="true" />

I have done exactly what you are trying to do, and it works for me.
 
Try using this in your template:

Rich (BB 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!
 
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.
 
Top Bottom