We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17959 ☆ A M B ☆
    • 57 Posts
    Magnatron [Maarten Wolzak] Reply #1, 16 years, 6 months ago
    One of the first things I always do when making a new install is extending the ’Inherit Parent Template’ plugin to first check the siblings.
    I rename it to ’Inherit Sibling or Parent template’

    Most of the time a sibling seems a much better reference because that will be at the same level. (Hence ’sibling’)

    /*
     * Inherit Template from Sibling or, if no siblings available, Parent
     * Written By Raymond Irving - 12 Oct 2006
     * Adapted by Maarten Wolzak - feb 2008
     *
     * Simply results in new documents inherriting the template 
     * of their first sibling (or parent folder if no siblings)
     * upon creating a new document
     *
     * Configuration:
     * check the OnDocFormPrerender event
     *
     * Version 1.0.1
     *
     */
    
    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnDocFormPrerender':
        if(($_REQUEST['pid'] > 0) && ($id == 0)) {
          if($sibl = $modx->getDocumentChildren($_REQUEST['pid'], 1, 0, 'template')){
            $content['template'] = $sibl[0]['template'];
          }else if($sibl = $modx->getDocumentChildren($_REQUEST['pid'], 0, 0, 'template')){
            $content['template'] = $sibl[0]['template'];
          }else if($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
            $content['template'] = $parent['template'];
          }
        }
        break;
    
      default:
        return;
        break;
    }
    


    I would be glad if this could be integrated in upcoming versions!

    Thanks,
    Maarten
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      This does seem like an excellent idea; it will solve the issue of having (for example) news items with one template as children of the main News resource with a different template.

      You’ve been hiding this for two years?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 17959 ☆ A M B ☆
        • 57 Posts
        Magnatron [Maarten Wolzak] Reply #3, 16 years, 6 months ago
        I thought it was so obvious I must have missed something. Never really got around to checking if anybody else would find it useful.

        At least it lasts smiley
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, thank you for that anyway. It’s gone right into my local store of MODx goodies.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4310
            • 2,310 Posts
            Excellent addition smiley
            The best ideas are often the simplest
              • 25663 MODX Staff
              • 12,272 Posts
              Kudos for a simple and elegant solution. Love it!
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 17959 ☆ A M B ☆
                • 57 Posts
                Magnatron [Maarten Wolzak] Reply #7, 15 years, 11 months ago
                HEY! You added it to the new version! shocked grin
                  • 21054
                  • 78 Posts
                  This is great! But... it doesn’t work when you’re creating a new resource from QuickManager on Evo.

                  i.e. A client goes to the "News" page and creates a new resource from the toolbar to start writing an article. If they forget to specify, the template defaults to "News Summary" instead of the "News Article". Is this just a matter of checking an special event for the plugin to listen to?
                    • 29076
                    • 615 Posts
                    I’m getting an error when using this plugin with the code copied from the first post:
                    syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING
                    
                    Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in /home/kjerraaq/public_html/manager/includes/document.parser.class.inc.php(790) : eval()'d code on line 21


                    Are there any other settings I should know about?

                    I’m using Evolution 1.05 on LAMP.
                      I think, thererfor I am! But what I am, and why...?
                      • 19369
                      • 1,098 Posts
                      I think this is a default feature of MODx 1.05, check here: Tools > Configuration > Site > Automatic Template Assignment