Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the ID of the "Root Resource", aka "Ultimate Parent", with slightly different feature set.
* @author @sepiariver
* GPL license, no warranties, no liability, etc.
* [[rootResource? &toPlaceholder=`root_resource`]]
* //followed by something like
* [[getResources? &parents=`[[+root_resource]]` ... ]]
$id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id'));
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, '');
$pids = array_reverse($modx->getParentIds($id));
$output = (isset($pids[1]) && !empty($pids[1])) ? $pids[1] : $id;
if (empty($toPlaceholder)) return $output;
$modx->setPlaceholder($toPlaceholder, $output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment