Thanks for your research.
It really logical, but I had to try a few times before it got to me: You need to declare the variable in pagelayout.tpl to access it in templates on same or higher level than the one that sets it.
Comments (2 historical)
Written by readers of the earlier documentation sites, kept as they were.
If you have trouble using scopes or namespaces, a simpler solution is to use the "persistent_variable" var:
- it is accessed as $persistent_variable in node templates
- it can be set directly in any template without having to be def()ined first
- it can be set() in an included template and it will be available in the including template
- it will even be available in another template included after the one where it is set
- it will be available in the pagelayout via $module_result.content_info.persistent_variable
the only drawback is that it is not easy to use in custom modules.
To store multiple values, just make it a hashmap containing all the desired values. Otoh if all you need to pass around between templates are strings, you might also investigate the set-block template function, which takes scope and namespace params. It works better than set.
Cookies on this website
This documentation stores what it needs to work: a session cookie when you sign in or keep a setting such as the help menu shown or hidden, the design you chose (Classic or Modern) and your language. Only if you agree, it also uses Google Analytics (through Google Tag Manager) to count visits; until then nothing is loaded from Google. Your choice is kept in a cookie for 6 months, and you can change it at any time under "Cookie settings" at the foot of every page. Details are in our Cookie Policy.
Always on
The session cookie for signing in and for forms, the cookies that keep your design and language, and the cookie that keeps this choice. They stay on because the website needs them; you can delete them in your browser settings at any time.
Google Analytics, loaded through Google Tag Manager (GTM-MPGWKTQV), counts visits and shows us which pages are read: the pages you open, the page you came from, your browser, device and screen size, and your approximate location derived from your IP address. Google processes the data for us and may transfer it to the USA. It sets the cookies _ga and _ga_* for up to 2 years. Off until you turn it on; when you turn it off again, Google is no longer loaded and these cookies are deleted.
Comments (2 historical)
Written by readers of the earlier documentation sites, kept as they were.
Re: Re: How to define global variables
Guillaume ·
This doesn't work for me, i can set the var but i cannot get the value.
Re: Re: Re: How to define global variables
Gaetano ·
If you have trouble using scopes or namespaces, a simpler solution is to use the "persistent_variable" var:
- it is accessed as $persistent_variable in node templates
- it can be set directly in any template without having to be def()ined first
- it can be set() in an included template and it will be available in the including template
- it will even be available in another template included after the one where it is set
- it will be available in the pagelayout via $module_result.content_info.persistent_variable
the only drawback is that it is not easy to use in custom modules.
To store multiple values, just make it a hashmap containing all the desired values.
Otoh if all you need to pass around between templates are strings, you might also investigate the set-block template function, which takes scope and namespace params. It works better than set.