Ad Templates Issue

Quiver

Active member
How come this works in forum_list template?

Code:
<xen:if is="{$TwistedPromotion_TopUser}">
<div class="section staffOnline avatarList">
  <div class="secondaryContent">
    <h3>{xen:phrase twistedpromotion_topuser}</h3>
    <ol>
    <xen:foreach loop="$TwistedPromotion_TopUser" value="$XTopUser">
    <li>
    <xen:avatar user="$XTopUser.user" size="s" text="{$XTopUser.username} ({xen:number $XTopUser.totalPosts})" class="Tooltip" title="{$XTopUser.username}" />
    <xen:username user="$XTopUser.user" rich="true" />
    <xen:if is="{$XTopUser.homepage} == ''">
<i>has not set their homepage.</i><br />
<a href="http://www.twistedpromotion.com/account/personal-details">Click to set your homepage.</a>
<xen:else />
Visit {$XTopUser.username}'s website:<br />
<a href="{$XTopUser.homepage}" target="_blank">{$XTopUser.homepage}</a>
</xen:if>
    </li>
    </xen:foreach>
    </ol>
  </div>
  </div>
</xen:if>

But when I try to call {$XTopUser.homepage} in ad_header template it doesn't work?
 
Basically this addon I made works with forum_list in the sidebar.
But I also have another feature in the Model PHP file which grabs a custom field.
Right? If I was to use {$XTopUser.banner}...as it's called...in the above template, it works fine.
But when I call the same from ad_header template it doesn't show anything at all. What's up? :(
 
I need to see the code.

Code:
<?php
class TwistedPromotion_TopUser_Controller_Public extends XFCP_TwistedPromotion_TopUser_Controller_Public
{
        public function actionIndex()
        {
                $response = parent::actionIndex();
 
                if ($response instanceof XenForo_ControllerResponse_View)
                {
                        $TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
                }
 
                $response->params += array('TwistedPromotion_TopUser' => $TwistedPromotion_TopUser);
                return $response;
        }
}
?>
 
Code:
<?php
class TwistedPromotion_TopUser_Controller_Public extends XFCP_TwistedPromotion_TopUser_Controller_Public
{
        public function actionIndex()
        {
                $response = parent::actionIndex();
 
                if ($response instanceof XenForo_ControllerResponse_View)
                {
                        $TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
                }
 
                $response->params += array('TwistedPromotion_TopUser' => $TwistedPromotion_TopUser);
                return $response;
        }
}
?>

You're not extending another existing class. Why are you using the XFCP Syntax?
 
You're not extending another existing class. Why are you using the XFCP Syntax?
Well, everything works in forum_list in the sidebar.
$XTopUser.homepage, $XTopUser.username etc. ;)
$XTopUser.banner also works. But I don't want to use $XTopUser.banner in the forum_list.
I want to use $XTopUser.banner in the ad_header template, but it doesn't work in that one. :(
 
Well, everything works in forum_list in the sidebar.
$XTopUser.homepage, $XTopUser.username etc. ;)
$XTopUser.banner also works. But I don't want to use $XTopUser.banner in the forum_list.
I want to use $XTopUser.banner in the ad_header template, but it doesn't work in that one. :(

I'm not sure what you are doing here. Are you defining a custom page or are you overriding an existing one? Nonetheless I'm not sure whether $response->params += array('TwistedPromotion_TopUser' => $TwistedPromotion_TopUser); is the proper way of adding a new parameter, but since it seems to be working for you in other cases I'll let that pass.

Is $response really an instance of XenForo_ControllerResponse_View? Have you checked that?
 
Basically the addon does this: http://forumpromotion.net/forum/viewtopic.php?f=43&t=102515
Earlier today I created a custom field allowing members to add a 468x60 banner URL in their UserCP.
Now, similar to how the above topic (see screenshot contained within) shows the user's homepage, right?
In much the same way, it will show the user's banner. It works. But I don't want the banner in the sidebar.
Obviously, as it's a 468x60 banner. I want everything else this addon does appearing in the sidebar though.
From the sidebar side of things everything is working exactly as I want it to. Are you currently with me?? ;)
But I want to display the banner side of things in the ad_header template (i.e. on the right, above the navbar).
However, when I use $XTopUser.banner it doesn't show anything. But it works as expected if I use in sidebar.
Basically, what's working in the sidebar isn't working in ad_header and I want it to work in ad_header as well.
 
Hi,
I want my ad_header template to contain:

Code:
<xen:hook name="ad_header" />
<xen:if is="{$TwistedPromotion_TopUser}">
<xen:foreach loop="$TwistedPromotion_TopUser" value="$XTopUser">
<a href="{$XTopUser.homepage}" target="_blank"><img src="{$XTopUser.userFieldValues.banner}" alt="{$XTopUser.username}"></a>
</xen:foreach>
</xen:if>
The $XTopUser is part of an addon I made.
Which seems to work except in ad templates.
 
Now the issue in the other thread has been resolved it maybe makes sense to continue here.

You should investigate template hooks.

There's no parameters available in that template but you can pass parameters to templates using template hooks.
 
Now the issue in the other thread has been resolved it maybe makes sense to continue here.

You should investigate template hooks.

There's no parameters available in that template but you can pass parameters to templates using template hooks.
I've viewed tutorials, including this one: http://xenforo.com/community/threads/how-to-use-template-hooks.13167/
I don't know what I'm doing wrong or not doing right, but I just don't understand what I need to do, or how to do it.
 
I'm not looking to create a hook for the addon.
I just want to edit ad_header template in XenForo admin panel.
Enter this data:

Code:
<xen:if is="{$TwistedPromotion_TopUser}">
<xen:foreach loop="$TwistedPromotion_TopUser" value="$XTopUser">
<a href="{$XTopUser.homepage}" target="_blank"><img src="{$XTopUser.userFieldValues.banner}" alt="{$XTopUser.username}"></a>
</xen:foreach>
</xen:if>
And for it to work.
But it's clearly not accepting the variables.
 
Now the issue in the other thread has been resolved it maybe makes sense to continue here.

You should investigate template hooks.

There's no parameters available in that template but you can pass parameters to templates using template hooks.
I added this to my Listener file (the same one I PMed you earlier).

Code:
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'ad_header')
        {
            $content .= '<xen:if is="{$TwistedPromotion_TopUser}">
<xen:foreach loop="$TwistedPromotion_TopUser" value="$XTopUser">
<a href="{$XTopUser.homepage}" target="_blank"><img src="{$XTopUser.userFieldValues.banner}" alt="{$XTopUser.username}"></a>
</xen:foreach>
</xen:if>';
        }
    }
Doesn't work.

I also created a CODE EVENT LISTENER in the Admin CP developer tab.
As instructed in Kier's tutorial video. So what exactly am I doing wrong? :(
 
You are close.

Create a new template e.g MyTemplate
Paste your template code into it.

In your template hook code use this:

$contents .= $template->create('MyTemplate', array());

Now that also won't work heh...

You see where I've got array() above? You should replace that with your TopUsers array. That means you'll need to grab that in exactly the same way you get it in your controller.

Overall there's much better ways of doing this but I suspect you probably want to just get this working first then we can improve on it.
 
You are close.

Create a new template e.g MyTemplate
Paste your template code into it.

In your template hook code use this:

$contents .= $template->create('MyTemplate', array());

Now that also won't work heh...

You see where I've got array() above? You should replace that with your TopUsers array. That means you'll need to grab that in exactly the same way you get it in your controller.

Overall there's much better ways of doing this but I suspect you probably want to just get this working first then we can improve on it.
Not working. :(

Code:
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'ad_header')
        {
            $contents .= $template->create('MyTemplate', array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage'], "userFieldValues" => $userFieldValues));
            $content .= '<a href="{$XTopUser.homepage}" target="_blank"><img src="{$XTopUser.userFieldValues.banner}" alt="{$XTopUser.username}"></a>';
        }
    }
 
Back
Top Bottom