We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    I guess that I could do this by modifying the InheritParentTemplate plugin but I was not successful. This is what I got, I added an check to identify the parent id by a constant value, otherwise the pluging should continue to work as before. In this case the container I want to set the default template for is id 12:
    <?php
    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnDocFormPrerender':
        if(($_REQUEST['pid'] > 0) && ($id == 0)) {
        	if($_REQUEST['pid'] == 12) { 
        		$content['template'] = "template name";
        	}
          	elseif ($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
            	$content['template'] = $parent['template'];
          	}
        }
        break;
    
      default:
        return;
        break;
    }
    ?>


    Anyone spot why this is not working?
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don&#39;t know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 7231
      • 4,205 Posts
      I found the problem, I need the template id not the template name. Now it works perfect. I wonder if I could use an array of container IDs to cover multiple containers.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 7231
        • 4,205 Posts
        Ok, just to finish up I added an array to be able to set multiple parents to have custom template.

        <?php
        global $content;
        $e = &$modx->Event;
        $containers = array(1,2,3); // container IDs for custom template
        $custom_tpl = 12; //custom template ID
        
        switch($e->name) {
          case 'OnDocFormPrerender':
            if(($_REQUEST['pid'] > 0) && ($id == 0)) {
            	if(in_array($_REQUEST['pid'], $containers)) { 
            		$content['template'] = $custom_tpl;
            	}
              	elseif ($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
                	$content['template'] = $parent['template'];
              	}
            }
            break;
        
          default:
            return;
            break;
        }
        ?>
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 7231
          • 4,205 Posts
          I wonder if I could use the "Plugin Configuration" panel to set the array and custom template variables rather than setting it directly in the code?
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]