We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I have a snippet that gets some constants from a Property Set and uses some formulas to crunch some form input and output results.

    I tried using this snippet as a FormIt hook (post-hook), but there is no way I can see to attach the specific property set.

    My next thought was to use a middle-man snippet as the hook, and within it call my snippet via $modx->runSnippet() - but I still see no way to attach the property set.

    Is there a way to do this? I know it can be done in tag format, so I'd assume it can be done programmatically as well.

      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: jrotering at Apr 25, 2013, 03:05 PM
      I have a snippet that gets some constants from a Property Set and uses some formulas to crunch some form input and output results.

      I tried using this snippet as a FormIt hook (post-hook), but there is no way I can see to attach the specific property set.

      My next thought was to use a middle-man snippet as the hook, and within it call my snippet via $modx->runSnippet() - but I still see no way to attach the property set.

      Is there a way to do this? I know it can be done in tag format, so I'd assume it can be done programmatically as well.
      As of MODX 2.2, you can call modX::runSnippet(), modX::getChunk() and modParser::getElement() with Element names that include the Property Set, e.g.

      $output = $modx->runSnippet('mySnippet@myPropertySet', $snippetProperties);
        • 38290
        • 712 Posts
        Wow, I'm glad opengeek beat me to this one because I was going to instruct how to do it the old fashion way. Learn something new everyday!
          jpdevries
          • 14883 ☆ A M B ☆
          • 450 Posts
          Quote from: opengeek at Apr 25, 2013, 04:36 PM

          As of MODX 2.2, you can call modX::runSnippet(), modX::getChunk() and modParser::getElement() with Element names that include the Property Set, e.g.

          $output = $modx->runSnippet('mySnippet@myPropertySet', $snippetProperties);

          This is excellent.

          So, just to be clear - if @myPropertySet has a property called 'foo', and I use the call you made above, can I access it from within 'mySnippet' via
          $scriptProperties['foo']
          ?

          And I'll get the 'myPropertySet' version of foo, rather than a version of foo that might be in the default property set for mySnippet?



            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: jrotering at Apr 25, 2013, 04:41 PM

            So, just to be clear - if @myPropertySet has a property called 'foo', and I use the call you made above, can I access it from within 'mySnippet' via
            $scriptProperties['foo']
            ?

            And I'll get the 'myPropertySet' version of foo, rather than a version of foo that might be in the default property set for mySnippet?
            That is correct, or via $foo. And any additional scriptProperties would also be passed to override any properties from the property set using that call (i.e. I am passing in the scriptProperties assigned to the calling Snippet, or hook).