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

Discussion in 'XenForo Development Discussions' started by querschlaeger, Oct 7, 2015.

  1. querschlaeger

    querschlaeger Member

    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 $hookParamsXenForo_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 $hookParamsXenForo_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?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Use template modifications.

    (Admin CP > Appearance > Template Modifications)

    Template hooks are deprecated.
     
  3. querschlaeger

    querschlaeger Member

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

    Brogan XenForo Moderator Staff Member

  5. querschlaeger

    querschlaeger Member

    Thank you all. :)
     

Share This Page