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

Ad Templates Issue

Discussion in 'Styling and Customization Questions' started by Quiver, May 14, 2013.

  1. Quiver

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

    Quiver Active Member

    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? :(
     
  3. tyteen4a03

    tyteen4a03 Well-Known Member

    Did you define $TwistedPromotion_TopUser array in $viewParams in the Controller?
     
  4. Quiver

    Quiver Active Member

    Well it works in the proper ad template.
    I want to use bits of it in another template.
    And it doesn't work in that "other" template.
     
  5. tyteen4a03

    tyteen4a03 Well-Known Member

    I need to see the code.
     
  6. Quiver

    Quiver Active Member

    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;
            }
    }
    ?>
     
  7. tyteen4a03

    tyteen4a03 Well-Known Member

    You're not extending another existing class. Why are you using the XFCP Syntax?
     
  8. Quiver

    Quiver Active Member

    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. :(
     
  9. tyteen4a03

    tyteen4a03 Well-Known Member

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

    Quiver Active Member

    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.
     
  11. Quiver

    Quiver Active Member

    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.
     
  12. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  13. Quiver

    Quiver Active Member

    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.
     
  14. Quiver

    Quiver Active Member

    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.
     
  15. Quiver

    Quiver Active Member

    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? :(
     
  16. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  17. Quiver

    Quiver Active Member

    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>';
            }
        }
     
  18. Chris D

    Chris D XenForo Developer Staff Member

    I'll just do it for you. It will be easier then you can see how it was done.

    Will be later though.
     
    BrokenChaos likes this.
  19. Quiver

    Quiver Active Member

    Ok. As this is so nearly finished and it's really frustrating me, so thanks. :)
     
  20. Quiver

    Quiver Active Member

    Perhaps you could just tell me how to do it?
    Although it's very kind of you to offer to help.
     

Share This Page