Hi I'm trying to output the folder parent name of a document as a piece of meta data..
IE
<meta itemprop="articleSection" content="[[!getResourceField? &id=`[[*parent]] &field=`pagetitle`]]">
With no luck.
I tried with just [[*parent]] but that just returns the id number.
Any ideas?
Thanks
[ed. note: markg last edited this post 8 years, 8 months ago.]
Content Creator and Copywriter
discuss.answer
Bobray has a great post on this here:
https://bobsguides.com/blog.html/2014/01/17/getting-a-parents-pagetitle/
Instead of pagetitle you could use it to get additional fields instead such as alias.
$output = $parentObj->get('alias');
To get all fields that you can then use as a placeholder simply call into an array
<?php
$output = '';
$tpl = $modx->getOption('tpl', $scriptProperties, 'ParentInfoTpl', true);
$parent = $modx->getObject('modResource', array('id' => $modx->resource->get('parent')));
if ($parent) {
$fields = $parent->toArray();
$output = $modx->getChunk($tpl, $fields);
}
return $output;
And then call your snippet and specify a tpl chunk
[[!ParentInfo? &tpl=`ParentInfoTpl`]]
[ed. note: lkfranklin last edited this post 8 years, 8 months ago.]
LK,
I just used Bob's snippet exactly as is and it worked perfectly.
Content Creator and Copywriter