Based on Everett’s work on the Wiki and suggestions for the docs, I’ve put up a snippet FAQ on Bob’s Guides:
http://bobsguides.com/modx-snippet-faq.html.
I tried to bring together stuff that was kind of scattered in the docs. Hopefully, it will head off some support requests and serve as a place to refer people to.
Let me know if you see any errors on the page or have suggestions for additions or improvements.
Great faq. One suggestion for "How can I access a parameter in the snippet call from inside the snippet. "
You can also access parameters of the current snippet from $modx->event->params. This is an associative array with the snippet parameter name as the key. This can be useful to access snippet parameter values from inside a function for instance. The one thing to note of course is that any changes made to the regular php variable is not going to be reflected in the modx->event->params array or visa versa (this may not be as obvious as it sounds to some)
-
☆ A M B ☆
- 2,475 Posts
Thanks Bob! That’s a great resource!
Quote from: TobyL at Jan 24, 2009, 08:34 AM
Great faq. One suggestion for "How can I access a parameter in the snippet call from inside the snippet. "
You can also access parameters of the current snippet from $modx->event->params. This is an associative array with the snippet parameter name as the key. This can be useful to access snippet parameter values from inside a function for instance. The one thing to note of course is that any changes made to the regular php variable is not going to be reflected in the modx->event->params array or visa versa (this may not be as obvious as it sounds to some)
Great suggestion. Done.! Thanks.
I also added more info about using classes and PHP4/PHP5 compatibility.
THANK YOU!! :-*
Modx rocks because of contributions just like this! 8)
//One thing to maybe add (unless its in there or the wiki and just basic) is what
ZAP told me; to add a "return" outside the function though modx otherwise would
output 1 for true...
http://modxcms.com/forums/index.php/topic,31363.msg190209.html#msg190209
Quote from: dev_cw at Jan 24, 2009, 06:23 PM
You can also access parameters of the current snippet from $modx->event->params.
I did not know this. So if I have a parameter named MyParam I can access it from within the snippet as $modx->event->MyParam?
Almost:
$someVariable = $modx->event->params['myParam'];
What is the event clause for?
I have a guess, but I might as well let someone who knows for sure answer this. The array is set in the document parser for modules, plugins, and snippets but, as far as I can tell, it’s never used in the MODx code.