We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12066
    • 48 Posts
    Hi guys,

    I'm struggling to get the snippet's name and the value of the property-set in the snippet.

    Let's say I've got the following snippet call placed in a resource:
    [[snippet@propset? &prop=`value`]]


    How do I retrieve the snippet's name and the value of the property-set within the code of the snippet?

    I want to have the value of the property-set, in the example this would be 'propset', available in my snippet as a variable.

    // All my script properties are in $scriptProperties
    var_dump($scriptProperties);
    // What I want is $propertysetValue (or similar)
    var_dump($propertysetValue);    // => string 'propset' (length=7)
    


    Thanks for any help. [ed. note: herooutoftime last edited this post 12 years, 8 months ago.]
      • 27708 MODX Staff
      • 2,502 Posts
      Can you show what the intended output is or result looks like? I am struggling to understand what problem you're trying to solve vs what you're asking to do (sometimes those are mutually exclusive). I could just be thick, though and it could be plainly obvious to others.
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Combining this post with https://twitter.com/herooutoftime/status/421266410333949952 it seems like you store some data in a component, and are using the property set's name to relate to that?

        If so, my advice would be to simply pass a property to the snippet call instead.

        [[snippet? &prop=`value` &set=`propset`]]

        var_dump($scriptProperties['set']);


        Quickly looking at the source of modScript->process you may be able of getting the name of snippet with $this->get('name') (though I seem to recall leaving in references to "$this" would actually result in fatal errors....) but the property set name does not seem to be stored anywhere; it's just processed and added to the properties.

        EDIT: The reference to $this being available is actually in the 2.3 source; that might be important to note and was confirmed on twitter [ed. note: markh last edited this post 12 years, 8 months ago.]
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 3749
          • 24,544 Posts
          You could also add a propset_name property to each property set. Then the name would be available with:

          $propset = $scriptProperties['propset_name'];


          I don't see why you would need the snippet's name, since any snippet-specific code in the snippet would only execute for that snippet, but Mark's method would get it for you.

            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