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

Template Parameters

Discussion in 'XenForo Development Discussions' started by Quiver, May 17, 2013.

  1. Quiver

    Quiver Active Member

    I am creating an addon which hooks into ad_message_below template.
    The addon works. Except for these variables:

    Code:
    <xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
    I need these variables to work. Please help.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Have you tried:

    <xen:if is="{$message.position} == 0 AND !{$message.conversation_id}">
     
  3. Brogan

    Brogan XenForo Moderator Staff Member

    I can confirm those conditionals work in the ad_ templates, I use them myself.

    Here's mine:
    Code:
    <xen:hook name="ad_message_below" />
     
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
        <xen:if is="!{$visitor.user_id}">
            <li class="message">
                <div class="messageUserInfo">
                    <div class="messageUserBlock">
                        <div class="avatarHolder" style="height: 102px; width: 102px">
                            <span class="helper"></span>
                            <img src="http://cliptheapex.com/data/avatars/m/0/2.jpg" alt="Avatar" height="96px" width="96px" style="border: 1px solid #C0C0C0; padding: 2px" />
                        </div>
                        <h3 class="userText">
                        <span style="font-weight: bold">Google AdSense</span>
                        <em class="userTitle" itemprop="title">Guest Advertisement</em>
                        </h3>
                        <span class="arrow"><span></span></span>
                    </div>
                </div>
                <div class="messageInfo primaryContent">
                    <div class="messageContent">
                        <article>
                            <blockquote class="messageText ugc baseHtml">
                                <script type="text/javascript"><!--
                                google_ad_client = "***";
                                /* Message Below */
                                google_ad_slot = "***";
                                google_ad_width = 728;
                                google_ad_height = 90;
                                //-->
                                </script>
                                <script type="text/javascript"
                                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                                </script>
                                <br /><br /><label for="LoginControl"><span style="font-weight: bold; color: #004400"><a href="login/" class="concealed noOutline">Log in or Sign up</a></span></label> to hide all adverts.
                            </blockquote>
                        </article>
                    </div>
                </div>
            </li>
        </xen:if>
    </xen:if>
     
    Chris D likes this.
  4. Quiver

    Quiver Active Member

    Doesn't help. The ad is still appearing in conversations and is still appearing after every post.
    Basically the external template which hooks into ad_message_below is ignoring parameters.
     
  5. Quiver

    Quiver Active Member

    I know it works in ad_message_below.
    I have a custom template which hooks into ad_message_below via a template listener.
    The template works. The only thing not working is the required parameters. :( Any idea?
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    EDIT: Oh I see. Can I see your Listener?
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That hook doesn't pass any params.

    You can access the template object to pull params from the content template, but that won't help you to know which post is currently being iterated. I don't know of any other context to help you to identify the first post. Maybe some one else knows.
     
    Chris D likes this.
  8. Quiver

    Quiver Active Member

    Here is the listener file:
    Code:
    <?php
    class TwistedPromotion_TagCloud_Listener_Listener
    {
        public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
        {
            if ($hookName == 'ad_message_below')
            {
                $contents .= $template->create('twistedpromotion_tagcloud');
            }
        }
    }
     
    ?>
    The external template twistedpromotion_tagcloud is working.
    The ad contained in that template shows in ad_message_below.
    But the parameters: <xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
    Which are ALSO defined in twistedpromotion_tagcloud ... well, they are NOT working. :(
    Therefore the ad is appearing after EVERY post and also in Personal Conversations.
    Whereas I want it appearing after the first post and not in conversations.
    Hence why I used: <xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">

    Ideas?
     
  9. Chris D

    Chris D XenForo Developer Staff Member

    Try this:
    PHP:
    <?php
    class TwistedPromotion_TagCloud_Listener_Listener
    {
        public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if (
    $hookName == 'ad_message_below')
            {
                
    $contents .= $template->create('twistedpromotion_tagcloud'$template->getParams());
            }
        }
    }
     
    ?>
     
  10. Quiver

    Quiver Active Member

    That's not working either:
    Look here; http://www.twistedpromotion.com/threads/fairy-tales-of-nadia-online.109/#post-683
     
  11. Chris D

    Chris D XenForo Developer Staff Member

    Yeah, thought so. It's basically what Jake said.

    You need to use the message_below hook instead, but slightly different to what I said earlier.

    This works:

    Code:
    		if ($hookName == 'message_below')
    		{
    			$contents .= $template->create('twistedpromotion_tagcloud', $hookParams);
    		}	
     
    Jake Bunce likes this.
  12. Quiver

    Quiver Active Member

    Thanks. That's fixed the message appearing after every post issue.
    However, it hasn't fixed it from appearing in Personal Conversations.
    Any idea how I can get AND !{$message.conversation_id}"> in <xen:if is="{$post.position} == 0 AND !{$message.conversation_id}"> to work?
     
  13. Chris D

    Chris D XenForo Developer Staff Member

    It will be: AND !{$post.conversation_id}

    $post and $message aren't used together. It's usually one or other.
     
  14. Quiver

    Quiver Active Member

    Thanks, that did the trick. :)
    I must say, that's twice I've hit a stumbling block with XenForo parameters today.
     

Share This Page