Global Template Variable

Global Template Variable

HappyWorld

Well-known member
semprot submitted a new resource:

Global Template Variable - How to create variables that can be accessed in all templates

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 &$params,...

Read more about this resource...
 
semprot submitted a new resource:

Can I use this to make other existing variables available to be retrieved on all templates ?

Let's say I wanna use existing $thread value in my 'navigation' template.
(the $thread value is retrieved from the corresponding page the navigation currently sits, indeed)

How can I achieve this with your add-on ?

PS: $thread variable is not available in 'navigation' template

thanks
 
Can I use this to make other existing variables available to be retrieved on all templates ?

Let's say I wanna use existing $thread value in my 'navigation' template.
(the $thread value is retrieved from the corresponding page the navigation currently sits, indeed)

How can I achieve this with your add-on ?

PS: $thread variable is not available in 'navigation' template

thanks
I don't think existing variables that are specific on specific templates can be made available on all templates using this method :)
However i could be wrong because i'm still learning XF too :D
 
Thanks for the simple example. I was trying make available a custom pulldown menu throughout the templates and was struggling with the syntax.
 
Hey @semprot, can I use this with custom userfields to call it anywhere in the forums?

This will really help me with a major issue. :)
 
Hey @semprot, can I use this with custom userfields to call it anywhere in the forums?

This will really help me with a major issue. :)
If you meant reading custom user fields within "template_create" function, i have tried to read $user & $visitor there, but it seems both variables are not recognized.
So there must be other way.
 
If you meant reading custom user fields within "template_create" function, i have tried to read $user & $visitor there, but it seems both variables are not recognized.
So there must be other way.

I know what I need but I don't know which way is better, I have also read the helper guide which can be found HERE but I don't know how to make it works, What I want is to create custom field for members to choose their user colors, and that color would show on every page of the site, like replacing usergroup color with the one chosen in the options.
 
Top Bottom