We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18367
    • 834 Posts
    Is there any way to specify that child templates are different from their parent template?

    I've tried both forceTemplate and inheritTemplate but neither seem to do anything.

    Mind you the instructions are a bit light and obtuse.

    Thanks
      Content Creator and Copywriter
      • 3749
      • 24,544 Posts
      I'm not sure what you're asking. Normally, new resources will inherit the parent's Template, but you can select any Template when you create them.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 18367
        • 834 Posts
        Sorry Bob I wasn't clear.

        I want to set a different template to the parent.

        And yes I know I can manually select a different one, but i want to know if I can set a parent's children to automatically use a different template.
          Content Creator and Copywriter
          • 3749
          • 24,544 Posts
          How would MODX know which template to use?

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 18367
            • 834 Posts
            Well supposedly those extras i mentioned allow you to set rules for your preferred template for the children of a parent.

            Although as I said, I haven't been able to figure out how to use them.

              Content Creator and Copywriter
              • 17301
              • 932 Posts
              Im not sure about those particular extras but if you use collections you can setup a custom view to use a default template and then also a specific child template.
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                • 3749
                • 24,544 Posts
                Also, a plugin attached to OnDocformSave should do it. Something like this (untested):

                /* Only  operate on new resources */
                if (!($mode == modSystemEvent::MODE_NEW)) {
                    return;
                } 
                
                /* Set all new resources not at the root 
                   of the tree to use template 12 
                */
                
                $parent = $resource->get('parent');
                if (! empty($parent)) {
                    $resource->set('tempate', '12');
                    $resource->save();
                
                }
                
                return '';


                This will set the template for *all* new resources on the site with parents to use template 12. If that's not what you want, you can add some conditions to the code so it only operates when you want it to.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 18367
                  • 834 Posts
                  Thanks guys,

                  but i finally figured out how to use Inherit Template
                  https://modx.com/extras/package/inherittemplate

                  by my usual method of stumble about and try things.

                  You know how it is when you first read some instructions: They make absolutely no sense and then after a few days of frigging about you find out how to do it, and then the instructions finally make sense, after the fact.

                  It's the tech gods messing with us.

                  PS the extra is a very elegant solution.

                    Content Creator and Copywriter