<?php
if ($mode != modSystemEvent::MODE_NEW) return;
/* Get parent ID */
$parentId = $resource->get('parent');
/* Get the TV object */
$tvObj = $modx->getObject('modTemplateVar', array('name' => 'ChildTemplate'));
/* Act only if there is a parent ID (i.e., doc is not at the root) and the TV object exists */
if ($tvObj) {
/* Get value of TV for parent */
if ($parentId) {
/* Get the TV's value for that ancestor */
$tv = $tvObj->renderOutput($parentId);
if ($tv) {
/* $tv is set -- use it for current resource's template value */
if (is_numeric($tv)) {
/* It's a number -- user it */
$tid = $tv;
} else {
/* It's a template name -- get the ID */
$t = $modx->getObject('modTemplate', array('templatename' => $tv));
if ($t) {
$tid = $t->get('id');
}
}
if($tid){
$resource->set('template', $tid);
$resource->save();
}
}
}
}$tv = $tvObj->renderOutput($parentId);
$tv = $tvObj->getValue($parentId);
Hi, in MODX Revo 2.2.0-pl2 defaultTemplateByParentTv Plugin doesn't work anymore. Is there a way to fix this?