Is there a way to use getOption() to get a snippet property or is it just for system settings?
$modx->getOption('optionname', $scriptProperties, 'default');The second argument is any associative array, which is searched before going to the MODx settings. The third argument is a default value.
What are the options for the second and third arguments?
Yep, any associative array will work.
Also, how about getting a property from a set that isn’t attached to a snippet?
Quote from: BobRay at Jul 19, 2009, 06:27 PMYep, any associative array will work.
. . . how about getting a property from a set that isn’t attached to a snippet?
$set = $modx->getObject('modPropertySet',PropertySetName');
$pSet = $set->getProperties();
$optionVal = $modx->getOption('PropertyName',$pSet,"Not Found");
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...
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.
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.
It’s working fine here in my tests, are you sure you don’t have caching issues?
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.