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

Global Template Variable 1

No permission to download
How to create variables that can be accessed in all templates

semprot

Active member
#1
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...
 
#3
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
 

semprot

Active member
#4
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
 

semprot

Active member
#8
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.
 

Cyb3r

Well-known member
#9
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.