Passing $hookParams - $user and $visitor

Chris D

XenForo developer
Staff member
Consider a template hook such as this:

            if ($hookName == 'member_card_stats')
                $contents .= $template->create('myTemplate_member_card', $hookParams);
And my template that looks like this:

<xen:if is="{$user.customFields.myPreference} == 'show' AND {$visitor.user_id}">
<dl class="pairsInline">
<dt>{xen:phrase content}:</dt>
<dd>{xen:string censor, $user.myContent}</dd>
The problem is here, the member_card_stats hook can't pass either the user or visitor params to the template.

I can handle this partially by adding the following to my hook:

$hookParams['visitor'] = XenForo_Visitor::getInstance();
This definitely (I have tested) passes the visitor params to the template.

What do I do to also pass the user params to the template?

I was able to get the user params working by adding:

$hookParams['user'] = XenForo_Visitor::getInstance();
But I can't get them working together. I need to be able to pass both user and visitor params - what am I missing?


Jake Bunce

XenForo moderator
Staff member
Admin CP -> Appearance -> Templates -> member_card

Add the red code:

Rich (BB code):
		<dl class="userStats pairsInline">
		<xen:hook name="member_card_stats" params="{xen:array 'user={$user}'}">
			<dt>{xen:phrase member_since}:</dt> <dd>{xen:date $user.register_date}</dd>
			<!-- slot: pre_messages -->
			<dt>{xen:phrase messages}:</dt> <dd><a href="{xen:link search/member, '', 'user_id={$user.user_id}'}" class="concealed">{xen:number $user.message_count}</a></dd>
			<!-- slot: pre_likes -->
			<dt>{xen:phrase likes_received}:</dt> <dd>{xen:number $user.like_count}</dd>
			<!-- slot: pre_trophies -->
			<dt>{xen:phrase trophy_points}:</dt> <dd><a href="{xen:link members/trophies, $user}" class="concealed OverlayTrigger">{xen:number $user.trophy_points}</a></dd>
			<xen:if is="{$canViewWarnings}">
				<dt>{xen:phrase warning_points}:</dt> <dd><a href="{xen:link members, $user}" class="concealed">{xen:number $user.warning_points}</a></dd>
Now $hookParams['user'] will exist.