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?
 
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.

Code:
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        //if ($hookName == 'ad_above_top_breadcrumb')
        //{
            //$params = $template->getParams();
            //$params += $hookParams;
            //$contents .= $template->create('twistedpromotion_banner', $params, array('TwistedPromotion_TopUser' => $TwistedPromotion_TopUser));
        //}
    }
This is also not working. :(
(even when it's uncommented)
 
This is kind of the idea I was talking about. I've based this on your Controller code somewhat. I have to say, it's not exactly the right way to do things, but this is based on the code you have so far in your Controller:

PHP:
	public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
	{
		if ($hookName == 'ad_header')
		{
			$TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
			
			$contents .= $template->create('MyTemplate', $template->getParams() += $TwistedPromotion_TopUser);
		}
	}
 
This is kind of the idea I was talking about. I've based this on your Controller code somewhat. I have to say, it's not exactly the right way to do things, but this is based on the code you have so far in your Controller:

PHP:
	public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
	{
		if ($hookName == 'ad_header')
		{
			$TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
			
			$contents .= $template->create('MyTemplate', $template->getParams() += $TwistedPromotion_TopUser);
		}
	}
Thanks I'll try this when I get home.
I'll let you know if it works, Chris. :)
 
Just a side note:

You need to ensure "MyTemplate" exists as a template in Admin CP > Appearance > Templates and contains the code that you wish to appear in the ad_header location.
 
This is kind of the idea I was talking about. I've based this on your Controller code somewhat. I have to say, it's not exactly the right way to do things, but this is based on the code you have so far in your Controller:

PHP:
 public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'ad_header')
{
$TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
 
$contents .= $template->create('MyTemplate', $template->getParams() += $TwistedPromotion_TopUser);
}
}
Fatal error: Can't use method return value in write context in /home/<my username>/public_html/library/TwistedPromotion/TopUser/Listener/Listener.php on line 17
 
It's ok was pretty much a lazy, copy paste error.

Correct way would be something like:

PHP:
	public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
	{
		if ($hookName == 'ad_header')
		{
			$TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();

			$params = $template->getParams();
			$params['TwistedPromotion_TopUser'] = $TwistedPromotion_TopUser;
			
			$contents .= $template->create('MyTemplate', $params);
		}
	}
 
It's ok was pretty much a lazy, copy paste error.

Correct way would be something like:

PHP:
 public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'ad_header')
{
$TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
 
$params = $template->getParams();
$params['TwistedPromotion_TopUser'] = $TwistedPromotion_TopUser;
 
$contents .= $template->create('MyTemplate', $params);
}
}
That fixed the error. But now it's still not displaying the banner.
I used the following (as wish to use ad_above_top_breadcrumb).
I've put something else in ad_header (paid PublicityClerks advert).

Code:
<?php
class TwistedPromotion_TopUser_Listener_Listener
{
    public static function listen($class, array &$extend)
    {
        if ($class == 'XenForo_ControllerPublic_Index')
        {
            $extend[] = 'TwistedPromotion_TopUser_Controller_Public';
        }
    }
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'ad_above_top_breadcrumb')
        {
            $TwistedPromotion_TopUser = TwistedPromotion_TopUser_Model_XTopUser::TwistedPromotion_TopUserArray();
 
            $params = $template->getParams();
            $params['TwistedPromotion_TopUser'] = $TwistedPromotion_TopUser;
           
            $contents .= $template->create('twistedpromotion_banner', $params);
        }
    }
}
 
?>
Now if you visit the top breadcrumb there's nothing there. :(
I have the template twistedpromotion_banner containing everything I need:

Code:
<a href="{$TwistedPromotion_TopUser.homepage}" target="_blank"><img src="{$TwistedPromotion_TopUser.userFieldValues.banner}" alt="{$TwistedPromotion_TopUser.username}"></a>
 
In your template type this:

{xen:helper dump, $TwistedPromotion_TopUser}

Save the template and check again - does it output anything? If so, what?
 
Exactly... as I thought...

So consider that you have exactly the same data as you have in the sidebar...

What do you think needs to be done differently in the twistedpromotion_banner template to make it work, just like you have it working in the sidebar? Is there anything different in the sidebar block code compared to your banner template?
 
Exactly... as I thought...

So consider that you have exactly the same data as you have in the sidebar...

What do you think needs to be done differently in the twistedpromotion_banner template to make it work, just like you have it working in the sidebar? Is there anything different in the sidebar block code compared to your banner template?
This is twistedpromotion_topuser 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="{$homeLink}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>

???
 
This is your clue:

Code:
		<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="{$homeLink}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>
 
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>
This works! :D :D :D :D :D
Thanks so much Chris. :D :D
Now to test it for a few hours.
 
Top Bottom