Get Any Field from the Parent of the Current Resource in MODX

In a previous article, I wrote about how to get the pagetitle of the current resource’s parent. It occurred to me that a more generic snippet that would get *any* field from the parent might be useful. Instead of the parent’s pagetitle, you might want its menuindex, longtitle, description, introtext (summary), or some other field.

This is a fairly minor modification of the previous snippet. The only real difference is that the name of the desired field is set as a snippet property and used as a variable in the snippet.

This tag goes where you want to display the parent’s field:

[code][[!getParentField? &field=`pagetitle`]][/code]

And here’s the snippet:

[code language=”php”]
/* getParentField snippet */

$parentObj = $modx->getObject(‘modResource’, $modx->resource->get(‘parent’));
$field = $scriptProperties[‘field’];

if ($parentObj) {
return $parentObj->get($field);
} else {
return ”;

MODX logo

See this page for a list of the available parent fields. You must use the exact field name (in all lowercase) for the field you want.

Here’s the more compact version:

[code language=”php”]
/* getParentField snippet */

$parentObj = $modx->getObject(‘modResource’, $modx->resource->get(‘parent’));
return $parentObj? $parentObj->get($scriptProperties[‘field’]) : ”;


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , | Posted under MODX, MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

Leave a Reply

Your email address will not be published. Required fields are marked *