Here is my non-elegant solution
What it does?
It helps the developer specify what template should the new child have. Works for how many levels you want but you need to create a diffrent plugin for each level
Use this plugin:
i harcoded the name of the TV: ChildTemplatePrograms. You can use the config solution if you want.
global $content;
$e = &$modx->Event;
$tvname = 'ChildTemplatePrograms';
switch($e->name) {
case 'OnDocFormPrerender':
if(($_REQUEST['pid'] > 0) && ($id == 0)) {
$sql= "SELECT IF(tvc.value!='',tvc.value,tv.default_text) as value ";
$sql .= "FROM " . $this->getFullTableName('site_tmplvars')." tv ";
$sql .= "INNER JOIN " . $this->getFullTableName('site_tmplvar_templates')." tvtpl ON tvtpl.tmplvarid = tv.id ";
$sql .= "LEFT JOIN " . $this->getFullTableName('site_tmplvar_contentvalues')." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = {$_REQUEST['pid']} ";
$sql .= "WHERE tv.name='{$tvname}'"; // AND tvtpl.templateid = " . $docRow['template']
$rs= $modx->dbQuery($sql);
$row = $modx->fetchRow($rs);
$tvChildTemplate = $row['value'];
}
if(is_numeric($tvChildTemplate)) {
$content['template'] = $tvChildTemplate;
} elseif($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
$content['template'] = $parent['template'];
}
break;
default:
return;
break;
}
Create a TV called ChildTemplatePrograms:
Just use a simple text TV and put the ID of the template you want the child to use. You can hide this tv later from the usual users.
Assign the TV to the parent template. In my case programs
Repeat these steps for all the levels you want to specify the child template. (do not forget to change the hardcoded TV name).
IMPORTANT:
- I am looking for a way to pass TV values to plugins. If we can find a way there will be no need to have a plugin for each level.
- In case it does not work make sure the plugins are called in the right order(Edit Plugin Execution Order by Event). The plugin for the parent should be called first.
Problem:
It seems that it works only if you use it on one container. If you try this on 2 multiple levels containers will not work. It’s related to the order of executions for the plugin. I have to differentiate somehow between the 2 folders. I hope to fix this soon