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

How to use Template Conditional Statements with Template Hook / Listener?

#1
Hello,

I created a very simple Code Event Listener to extend a template:

PHP:
<?php
class Demo_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        switch($hookName)
        {
            case 'ad_above_content':
            {
                $contents .= 'Lorem Ipsum';
                break;
            }
        }
    }
}
Works without a problem. But how can I use Conditional Statements here?

This does not work (show the text to guests only):

PHP:
<?php
class Demo_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        switch($hookName)
        {
            case 'ad_above_content':
            {
                $contents .= '<xen:if is="!{$visitor.user_id}">Lorem Ipsum</xen:if>';
                break;
            }
        }
    }
}
Is there a way to get the content of $visitor object?
 

Chris D

XenForo developer
Staff member
#2
Use template modifications.

(Admin CP > Appearance > Template Modifications)

Template hooks are deprecated.
 
#3
Ok, good to know. :)

It seems with TMS I can search and replace some stuff. But what shall I search in the template ad_above_content? It has no really content...
Are there any example and/or tutorials about TMS?