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

Unmaintained Global Template Variable 1

How to create variables that can be accessed in all templates

  1. semprot
    Compatible XF Versions:
    • 1.4
    This is a simple example about how to create variables that can be accessed in all templates.

    This code uses "template_create" listener.
    On this code, 2 variables are created, which are "$is_handsome", and "$is_fat".
    Both variables are set directly within
    Code:
    /library/Semprot/GlobalTemplateVariable/Listener.php
    PHP:
    <?php
    class Semprot_GlobalTemplateVariable_Listener
    {
        public static function 
    template_create(&$templateName, array &$paramsXenForo_Template_Abstract $template)
        {
            
    $params['is_handsome'] = true;
            
    $params['is_fat'] = false;
        }

    }
    And in your template (in my case, i use in my "PAGE_CONTAINER" template), you can use this conditional code.

    PHP:
    <xen:if is="{$is_handsome}">
    You are handsome.
    <
    xen:else />
    You are not handsome.
    </
    xen:if>

    <
    xen:if is="{$is_fat}">
    You are fat.
    <
    xen:else />
    You are not fat.
    </
    xen:if>
    sheel, Apt Irrelevance and Alfa1 like this.