Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
collection of modx parent snippets
GetParentAlias
$output = '';
/* Get the current resource's 'parent' field */
$parentId = $modx->resource->get('parent');
/* Get the parent object */
$parentObj = $modx->getObject('modResource', $parentId);
/* If we have the parent,
get and return the alias */
if ($parentObj) {
$output = $parentObj->get('alias');
}
return $output;
-----
GetParentPagetitle
$output = '';
/* Get the current resource's 'parent' field */
$parentId = $modx->resource->get('parent');
/* Get the parent object */
$parentObj = $modx->getObject('modResource', $parentId);
/* If we have the parent,
get and return the pagetitle */
if ($parentObj) {
$output = $parentObj->get('pagetitle');
}
return $output;
-----
<?php
$output = '';
$id = $modx->getOption('id', $scriptProperties);
$idObj = $modx->getObject('modResource', $id);
$parentId = $idObj->get('parent');
$parentObj = $modx->getObject('modResource', $parentId);
$gId = $parentObj->get('parent');
$gObj = $modx->getObject('modResource', $gId);
if ($gObj) {$output = $gObj->get('pagetitle');}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.