/*
Based on inherit Parent Plugin from Raymond Irving
Author : heliotrope
*/
global $content;
$e = &$modx->Event;
switch($e->name) {
case ’OnDocFormPrerender’:
if(($_REQUEST[’pid’] > 0) && ($id == 0)) {
$tv = $params[’tvSource’];
//check published status for parent
$status = $modx->getPageInfo($_REQUEST[’pid’],0,’published’);
if($inherit = $modx->getTemplateVar($tv,’*’,$_REQUEST[’pid’],$status[’published’])) {
$content[’template’] = $inherit[’value’];
}
}
break;
default:
return;
break;
}
2/ in defaut options:
@SELECT templatename,id FROM [+PREFIX+]site_templates
@SELECT templatename,id FROM [+PREFIX+]site_templates
Why isn’t this in the repository; it’s a great resource! How’s it differ from http://modxcms.com/automaticTpl-2155.html which I just found in searching for this thread? TongueThe main difference I can see so quickly is that automaticTpl will crawl up the tree to find a parent which has the TV set instead of only looking at the direct parent. You can also set multiple templates for several levels of parents. So if you create a page two levels down it can inherit a different template than if you create a page 1 level down, while you only set one TV in the topmost parent. The disadvantage is that filling in the TV is more archaic, you need to know the template ids and fill them in manually.
@EVAL $sql = 'SELECT templatename,id FROM '.$modx->db->config['table_prefix'].'site_templates';$v = $modx->db->query($sql);while ($rows = mysql_fetch_row($v)) $a[] = $rows; array_unshift($a,array('','')); return $a;
<?php /* Based on inherit Parent Plugin from Raymond Irving Author : heliotrope Checking multiple levels of parents added by TobyL */ global $content; $e = &$modx->Event; switch($e->name) { case 'OnDocFormPrerender': $pid = intval($_REQUEST['pid']); if(($pid>0) && ($id == 0)) { $tv = $params['tvSource']; $levels = $params['levels']?intval($params['levels']):10; $parentIds= $modx->getParentIds($pid,$levels); array_unshift($parentIds,$pid); //add current pid to top of parents foreach($parentIds as $id){ //check published status for parent $status = $modx->getPageInfo($id,0,'published'); if($inherit = $modx->getTemplateVar($tv,'*',$id,$status['published'])) { $content['template'] = $inherit['value']; break; } } } break; default: return; break; } ?>
This discussion is closed to further replies. Keep calm and carry on.