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

Passing $hookParams - $user and $visitor

Discussion in 'XenForo Development Discussions' started by Chris D, Jun 19, 2012.

  1. Chris D

    Chris D XenForo Developer Staff Member

    Consider a template hook such as this:

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

    HTML:
    <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>
    </dl>
    </xen:if>
    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:

    PHP:
    $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:

    PHP:
    $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?

    Thanks
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Admin CP -> Appearance -> Templates -> member_card

    Add the red code:

    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>
    			</xen:if>
    		</xen:hook>
    		</dl>
    
    Now $hookParams['user'] will exist.
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You might also be able to use this:

    Code:
    $template->getParam('user')
    
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Thanks Jake.

    Is this the only way?

    I want to avoid template edits if possible.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    Ah, thanks, I will try that.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Worked perfectly, thanks Jake :D
     

Share This Page