What you are expecting to happen here is for Modx to automatically process your ID & PARENT placeholders and pass them into your snippet. Modx will not do that for you, you either have to pass them in expolicitly in the $scriptProperties array ~or~ as Marvin pointed out get those properties from the modResource object (which modx will assume to be the current resource)
To pass them explicitly, add the placeholders to your snippet call:
[[~MyCustomSnippet? &id=`[[*id]]` &parent=`[[*parent]]`]]
In that situation Modx WILL populate the placeholders when it parses your page, template or chunk (wherever you happen to have called the snippet.
If you are dealing with the ID & PARENT for the CURRENT resource; Marvin's example will work, though I do believe you have to get the current resource object first.
$resource = $modx->getObject('modResource');
you would have to check the docs on that one. (or test it)
UPDATE
The three of us worked this out in a chat & came up with the following solution:
By calling the snippet this way:
[[!MyCustomSnippet? &id=`[[*id]]`]]
The contents of the snippet:
<?php
$id = isset($scriptProperties['id']) ? $scriptProperties['id'] : FALSE; // get id passed with snippet
$exhibitions = array(20,21,24);
if(!$id){
$id = $modx->resource->get('id'); // get the current resource id if it was not passed
}
$resource = $modx->getObject('modResource', $id); // get the resource object
$parent = $modx->resource->get('parent'); // get the parent id from the resource object
$output = '';
if ($id == 5) {
$chunk = "listExhibitions";
}
if (in_array($parent, $exhibitions)) {
$chunk = "Exhibitions";
}
$output = $modx->getChunk($chunk);
return $output;
That will use the ID passed in the snippet call OR assume the current resource if the id is not passed & get the parent ID from the resource object based on that.