We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21255
    • 215 Posts
    I needed backend-function which automatically selects the template of the parent document (instead of using the system-wide default template) if the user creates a blank page. This is what I got - hope, this is kind of useful for someone:
    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnDocFormPrerender':
        if(($_REQUEST['pid'] > 0) && ($id == 0)) {
          if($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
            $content['template'] = $parent['template'];
          }
        }
        break;
    
      default:
        return;
        break;
    }
    
      • 25663 MODX Staff
      • 12,272 Posts
      that’s very cool indeed.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 34162
        • 1 Posts
        That is really cool but how do you use it!

        Thanks
          • 6726
          • 7,075 Posts
          Yeah, I thought it would automatically set the template of the parent when selecting "Create a document here" but it does not...

          How do we use it ?
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 32241
            • 1,495 Posts
            It work on mine though.
            It will automatically set the default template according to the parent template, during the creation of new doc/folder on backend.
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 6726
              • 7,075 Posts
              I’ll check then, it’s probably me doing something wrong...
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
                • 31337
                • 258 Posts
                Great code, thanks! Very useful stuff for multi-template site.

                One additional instruction for using this (since it wasn’t obvious to me): Look at the tab on the Plugin entry page that’s labeled "System Events". Go into that tab and check "OnDocFormPrerender" on that page and then this works just fine.
                  • 25663 MODX Staff
                  • 12,272 Posts
                  Nice indeed ... added as rev 725 for 0.9.2 release. smiley
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 33453
                    • 141 Posts
                    This is incorrectly credited to Ray Irving in 0.9.2, also the date is 12 Oct 2006.

                    I know Modx is the future, but that’s stretching a point grin!