I’ve been playing with the new snippet properties and have to say the whole concept is fantastic. I love it. The user interface is a little rough around the edges and I assume that it’s not ready for bug reports yet, but the proof-of-concept seems to be pretty solid. After looking at how the properties are shoehorned into a single DB field, I’m both *very* impressed and glad I didn’t have to do the coding.
In Revolution, snippets can still be controlled as they were in 0.9.6, with parameters, but developers now have the option to have the default values set via a grid in the Manager. For snippets meant for use by naive users, you have the option to let some users set the options in the grid and use no parameters at all in the snippet call, while others use parameters to override the default options. Another plus is that the grid can serve as a complete parameter list that the user doesn’t have to hunt down -- complete with descriptions, default values already set, and, optionally, a drop-down list of possible values. No backticks, no ampersands, no worries about typos, case-sensitivity, or formatting.
In your snippet, you can just do:
$obj = $modx->getObject('modSnippet',array('name'=>'snippet-name-here'));
$myConfig= $obj->getProperties();
Then in your code, any property value set in the grid is available like so:
if ($myConfig['property-name-here']) {
doSomething();
}
As usual, I have questions and a thought or two.
First, when creating properties from a snippet or build script, what should go in the "options" field? I’m guessing "0,1" for a boolean and maybe "" for a textfield. Can this field be omitted in the array that goes to setProperties()?
Second, I see combo-boolean as an option but not just boolean. In the current implementation, users can type anything at all for the value of one of these. Will there be a way to have a straight boolean where they can only pick yes and no and have the values set to 1 and 0?
Wishlist:
Since these are default properties, I’d like to override them with values set in the snippet call. An overrideProperties() method that would automatically get the parameters and the properties of the current snippet, do the replacements, and return the merged array would be very cool. If it would let me optionally name the snippet to get the properties from, that would be even cooler (yeah, I actually have a use for that

).
A popup or js expansion for the description field in the grid so it can contain more information about the property and how to use it.
Import and export would also be nice, but not critical.
Here’s some working code that sets and gets properties in case people are curious. I had to guess at how to do it so don’t take this as the proper way.
global $modx;
/* get the snippet object */
$obj = $modx->getObject('modSnippet',array('name'=>'TestSnippet'));
if (!$obj) {
return("Object not found<br>");
}
/* set and save some properties */
$props = array(
array(
'name'=>'isCool',
'desc'=>'Is this thing cool, or what?',
'type'=>'combo-boolean',
'options'=>"",
'value'=> true
),
array(
'name'=>'howCool',
'desc'=>'Coolness description here',
'type'=>'textfield',
'options'=>"",
'value'=> 'The best thing since sliced bread'
)
);
$obj->setProperties($props);
$obj->save();
/* get and display the properties */
$propArray = $obj->getProperties();
foreach ($propArray as $key=>$value) {
$output .= $key . ": " . $value . "<br>";
}
return $output;
Of course, you can also set the properties in the GUI grid on the properties tab of the snippet create/edit page (you may need the latest SVN version).