-
☆ A M B ☆
- 3,112 Posts
As I start learning the Revo APIs, I found that there is a ’magic’ variable in entire page-requests: the
$scriptProperties.
This variable is kind of a global variable for injecting values into the getOption() function.
I found a weird situation here :
Support/Comments for FirstChildRedirect 2.2-pl, which I couldn’t get the perfect answer (either).
While Revolution introduces a new term for me:
’wrapping snippet’, where the &element and &elementClass pour more sugar into it, I’d like to know about
how the $scriptProperties gets the right value from the chaining snippets.
Let’s say both snippets have the same parameter called
&sortby, which appears as a popular parameter, where the default values are different.
Rico
Genius is one percent inspiration and ninety-nine percent perspiration.
Thomas A. Edison
MODx is great, but knowing how to use it well makes it perfect!
www.virtudraft.com
Security, security, security! |
Indonesian MODx Forum |
MODx Revo's cheatsheets |
MODx Evo's cheatsheets
Author of
Easy 2 Gallery 1.4.x,
PHPTidy,
spieFeed,
FileDownload R,
Upload To Users CMP,
Inherit Template TV,
LexRating,
ExerPlan,
Lingua,
virtuNewsletter,
Grid Class Key,
SmartTag,
prevNext
Maintainter/contributor of
Babel
Because it's hard to follow all topics on the forum, PING ME ON TWITTER
@_goldsky if you need my help.
The $scriptProperties array is just an array containing properties for the snippet. It’s not really magic (although it can look that way).
It’s not really tied to getOption() in any way, which can search any array. getOption() searches settings (system, user, & context) by default but if you send it an array as an optional argument, it will search that array too so it’s convenient to use it to search the $sriptProperties array.
Here’s how the $scriptProperties array is created:
When a snippet is called with a tag, MODx gets the default properties of the snippet and places them in the $scriptProperties array. Then it merges in any properties in any attached property set (specified with @propertySetName in the tag), then it merges in the individual parameters sent in the snippet tag (if any). As each successive set of values comes in, they will overwrite ones with the same name that are already there.
So, parameters in the tag have the highest precedence, attached property sets next, and default properties last.
When a snippet is run with runSnippet() the default properties of the snippet being called are added first, then any sent as the second argument to runSnippet().
So, the same precedence as above.
The scope of the properties is local to the snippet they’re in, so they shouldn’t collide even with nested snippets called with runSnippet(). The properties are arguments to a function (runSnippet()) so their scope is the code of that function, and just to avoid confusion, inside the runSnippet() function the variable name for the array is $params, not $scriptProperties.
If you set that property in the getPage tag, it should be passed through to the snippet getPage is running:
[[!getPage? &parents=`12` etc.]]
Wouldn’t that happen automatically if it’s in the getPage tag?
Arriving in the $scriptProperties array, it should override any default properties or properties in property sets. The target snippet would likely set it from the $scriptProperties array, no?
-
MODX Staff
- 10,725 Posts
Sorry, right, getPage itself does what I describe, I was just saying in general, to pass $scriptProperties to a snippet being called via runSnippet() requires you to pass it in.