We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Is there a way to use getOption() to get a snippet property or is it just for system settings?
      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 Jul 19, 2009, 02:06 AM

      Is there a way to use getOption() to get a snippet property or is it just for system settings?
      $modx->getOption('optionname', $scriptProperties, 'default');
        • 3749
        • 24,544 Posts
        Thanks.

        What are the options for the second and third arguments?

        The only docs I’ve been able to find for getOption show it with a single argument.


        Also, how about getting a property from a set that isn’t attached to a snippet?
          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 Jul 19, 2009, 06:27 PM

          What are the options for the second and third arguments?
          The second argument is any associative array, which is searched before going to the MODx settings. The third argument is a default value.

          Quote from: BobRay at Jul 19, 2009, 06:27 PM

          Also, how about getting a property from a set that isn’t attached to a snippet?
          Yep, any associative array will work.
            • 3749
            • 24,544 Posts
            Quote from: OpenGeek at Jul 19, 2009, 07:01 PM

            Quote from: BobRay at Jul 19, 2009, 06:27 PM

            . . . how about getting a property from a set that isn’t attached to a snippet?
            Yep, any associative array will work.

            Is there an easier way than this to get a property value from a named set?

            $set = $modx->getObject('modPropertySet',PropertySetName');
            $pSet = $set->getProperties();
            $optionVal = $modx->getOption('PropertyName',$pSet,"Not Found");


            I was hoping for something like:

            $modx->getProperty(’PropertySetName’,PropertyName’,’default’); wink
              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
              I don’t understand the scenario?? Why would you try and get a property from a specific property set? Property sets are assigned to things in context and should never need to be directly accessed like that...
                • 3749
                • 24,544 Posts
                Quote from: OpenGeek at Jul 20, 2009, 01:31 PM

                I don’t understand the scenario?? Why would you try and get a property from a specific property set? Property sets are assigned to things in context and should never need to be directly accessed like that...

                Now that property sets can be attached to chunks and other elements, it seemed to me that here’s a need to access them directly, either by name or by going through the element.

                Imagine a series of chunks, each with its own property set named after the chunk. There could be a single snippet that does something different with each chunk depending on the settings in the chunk’s property set.

                I can also imagine uses for property sets that aren’t attached to anything as a simple way to permanently store small amounts of data.

                BTW, what’s the method, then, for accessing a chunk or TV’s properties if not doing it by the name of the property set?
                  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 Jul 20, 2009, 05:58 PM

                  Now that property sets can be attached to chunks and other elements, it seemed to me that here’s a need to access them directly, either by name or by going through the element.

                  Imagine a series of chunks, each with its own property set named after the chunk. There could be a single snippet that does something different with each chunk depending on the settings in the chunk’s property set.

                  I can also imagine uses for property sets that aren’t attached to anything as a simple way to permanently store small amounts of data.

                  BTW, what’s the method, then, for accessing a chunk or TV’s properties if not doing it by the name of the property set?
                  When a Chunk or TV (or even a Template) is processed, placeholders are set for it’s properties within the scope of that element, and removed (or restored if any were overwritten) when processing of that element is completed. I had envisioned that passing properties and/or other associative array data from a Snippet down through to other "dependent" Snippets, Chunks, or even TVs would be the most common usage patterns for multi-element components. Or if the top level call was a Chunk or TV with a property set applied, that "dependent" Snippets, etc. would make use of the placeholders via the placeholder-related API methods.

                  That said, a $modx->getProperty() method might be useful to expand the potential uses of Property Sets outside of normal parsing patterns. Great thoughts.
                    • 3749
                    • 24,544 Posts
                    Quote from: OpenGeek at Jul 20, 2009, 07:01 PM


                    When a Chunk or TV (or even a Template) is processed, placeholders are set for it’s properties within the scope of that element, and removed (or restored if any were overwritten) when processing of that element is completed.

                    Maybe I’m misunderstanding, but I can’t get this to work (though it’s a very cool idea). I attached a property set to a chunk, then put [[+propertyName]] in the chunk and included the chunk in a document. There’s no output where the tag is. I also tried [[++propertyName]] and [[*propertyName]] for good measure.

                    Is this the correct method?

                    I think it’s a bug in attaching properties to elements - the property sets don’t seem to stick.

                      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 Jul 21, 2009, 03:32 AM

                      Maybe I’m misunderstanding, but I can’t get this to work (though it’s a very cool idea). I attached a property set to a chunk, then put [[+propertyName]] in the chunk and included the chunk in a document. There’s no output where the tag is. I also tried [[++propertyName]] and [[*propertyName]] for good measure.

                      Is this the correct method?

                      I think it’s a bug in attaching properties to elements - the property sets don’t seem to stick.
                      It’s working fine here in my tests, are you sure you don’t have caching issues?