We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ 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.
      • 3749
      • 24,544 Posts
      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.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 59
        • 10 Posts
        Hi, I am having a problem with $scriptProperties.

        I am trying to overwrite the default properties for getPage as follows:

        $scriptProperties = array('parents' => $parents);
        $page = $modx->runSnippet('getPage', $scriptProperties);
        


        I am passing $parents to this snippet from another snippet. No matter what I have tried I can’t seem to get it to set or overwrite the default ’parents’ value. Am I missing something obvious? laugh

        Edit: Apologies. embarrassed I have just realised that I need to set all values in the array, not just this 1.
          • 3749
          • 24,544 Posts
          If you set that property in the getPage tag, it should be passed through to the snippet getPage is running:

          [[!getPage? &parents=`12` etc.]]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: BobRay at Mar 16, 2011, 02:24 PM

            If you set that property in the getPage tag, it should be passed through to the snippet getPage is running:
            Only if you pass it through to runSnippet() though without changing the value of it first.
              • 3749
              • 24,544 Posts
              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?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 22303 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.