-
MODX Staff
- 10,725 Posts
Use placeholders to share data across scripts; plugins and snippets are eval()’d currently, and are run in there own variable scope, so you will not have access to the PHP variables directly outside of each script. Besides, globals are bad, ummmmkaaayyyy?!
@KBtechnics: What OpenGeek said. You can use MODx placeholders as you would global PHP vars, and you can also set session vars the same as you would outside of MODx. So your plugin code would be $modx->setPlaceholder(’aaaaa’,1); and you could then use that in any parsed output as [+aaaaa+] or get its value in a snippet using the getPlaceholder method.
mmmmkaaaayyy!
And how about functions? Which method is suggested to define a function in a (plugin?) and let it be usable in other (snippets?)?
I see that inside many useful snippets, many useful general-purpose functions are defined and used. I mean debug functions, check-permission functions and so on. Wouldn’t it be better if those functions were defined in a xx plugin, and the snippet(s) making use of them were community-shared with the plugin too? Maybe this could lead to a smarter development of new snippets, aided by shared plugins.
In a more strict sight, I’d like to build some snippets. They’d like to use general-purpose functions that I’d like to define once for all (and maybe share tomorrow, if good).
As you can see I am a newbie in modX, but I’d like to start in the most polite way of building. Too many times I said "ooh how easier it would have been if I just knew this before!", not talking just about sex.
thanks