-
- 145 Posts
Is there a way I can declare a variable that can be used in different snippets, plugins, etc? I want to share just one value that is defined once in one place. Any ideas?
Thanks in advance.
-
- 145 Posts
No worries, I found my answer... of sorts:
http://modxcms.com/forums/index.php/topic,1839.0.html
Anyone know of a better way?
You could create a plugin that sets $modx->documentObject[’myVariable’] = ’myValue’ and set it to use the onWebPageInit (or whichever one of those events would work) then you can just access it wherever you need it.
-
- 145 Posts
That’s better! That’s what I need! Thanks Susan.
you might need to fiddle with which event to use; I’m a little hazy on just where these get triggered.
You can also use the placeholder technique you found in that link in a plugin in the OnWebPageInit event as well. To insure the placeholder value you want to get back is available before the page is even loaded, cached or not.
Oh, and I wouldn’t use the documentObject to do it. That’s what palceholders are for, adding additional, custom data to a request. Modifying the core documentObject array could have potential consequences and might not be a compatible way of approaching the problem in future releases.
-
- 145 Posts
Quote from: OpenGeek at Feb 19, 2006, 08:29 PM
Oh, and I wouldn’t use the documentObject to do it. That’s what palceholders are for, adding additional, custom data to a request. Modifying the core documentObject array could have potential consequences and might not be a compatible way of approaching the problem in future releases.
Placeholders it is then! Thanks a lot team.
Didn’t know placeholders were so flexible and powerful. Definitely better than playing around with the core systems.
-
- 1,495 Posts
Another solution will be to use $_GLOBAL[’your_var_name’]
But you need to make sure that there is no global var with that name yet, and make the name as unique as possible.
-
- 145 Posts
Quote from: Djamoer at Feb 19, 2006, 09:05 PM
Another solution will be to use $_GLOBAL[’your_var_name’]
But you need to make sure that there is no global var with that name yet, and make the name as unique as possible.
Perhaps by using a prefix for MY variables. e.g.
$_GLOBAL[’kk_your_var_name’].