We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    Hi all,

    Template Rules is a plugin used to:
    1. define the default template when a document(child) is created.
    2. control the values of the "Uses Template" field.


    NOTE: you can hide the Template Rules chunk from other users using the "Access permissions" functionality. You will have to create different user groups.

    Download here
      • 25663 MODX Staff
      • 12,272 Posts
      Cipa, just to be clear, could this function exactly as an enhanced replacement for Inherit Parent Template? If so it’d be a wonderful bit to update for the Core distribution.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 5340
        • 1,624 Posts
        yes

        it can be done.

        But I personally think that there are a couple of things that need to be implemented.

        1. When a container uses this functionality and the dropdown is limited to the defined templates and a document is using a different one, when saving the document the template will change because it’s not in the configured list. This can be easily achieved.


        2. we can expand the limit template list functionality to the root container/documents.
        An additional TV will be needed or we can use the same but the syntax will be a bit more complicated.

        Using an additional TV we can define a simple list of of ids: 14,15. When you edit the root container only these templates will be visible in the dropdown.

        3. permissions for different groups - not needed as you can hide TVs with modx

        Any other ideas are welcomed.
          • 5340
          • 1,624 Posts
          bug fix
          please update
            • 11316
            • 81 Posts
            I was directed over from my previous post - http://modxcms.com/forums/index.php/topic,39455.0.html

            I am trying to figure out a way to have a my client (editing Container) click Uses Template: (Green) Have it change to GREEN and change the children documents 1 level down to GREEN also. Basically this Container has this template - if I change it to green from blue all documents under this container will become blue template also.

            Any help would be greatly appreciated.
              • 5340
              • 1,624 Posts
              1. You can teach your client to use Document Manager. You can pass a list of ids and change the template for all of them.

              2. You have to built a plugin that is based on Templates Rules + some customization.

              Here’s how I think you should do it:

              a. create a new TV called: stickyTemplate (or similar) - This should be Yes/no probably a checkbox
              b. Apply it to the container
              c. extend Template Manager to something like

              case ’OnLoadWebDocument’:


              if the parent has stickyTemplate to yes

              get the template id of the parent
              get the template

              $modx->documentContent = the above template;

              break;

              If you want that when you edit a child the template is Blue instead of the default Red you should modify a bit the Template Rules Plugin to detect the sticky TV value and output the appropriate value for ’OnDocFormRender’ event




                • 3689
                • 264 Posts
                When im on my projects page it says Uses Template: "Projects" instead of "Project Details" and I went through the installation instructions about 4 times very slowly so im not sure what to do.. I have the "Template Rules" field at the bottom of the "Projects" page and put in "10" which is my "Project Details" template.. what else could it be?
                  • 5340
                  • 1,624 Posts
                  Hi BnH,

                  I’m using this plugin on at least 5 projects and I do not have a problem with it. I’m not sure what is happening but I could have look if you send me a user name and pass to login into your modx install.

                    • 26931
                    • 2,314 Posts
                    anonymized-26931 Reply #9, 17 years ago
                    Hi cipa,

                    thanks for sharing your plugin! smiley

                    i read in the instructions:
                    This plugin has no effect on root document/containers
                    could this be a possible feature in future releases?

                    j
                      • 3689
                      • 264 Posts
                      Quote from: cipa at Sep 19, 2009, 07:28 AM

                      Hi BnH,

                      I’m using this plugin on at least 5 projects and I do not have a problem with it. I’m not sure what is happening but I could have look if you send me a user name and pass to login into your modx install.



                      Is this plugin suppose to work on the front end or only from the back? It seems to be working on the back end so unless its suppose to work on the front end I think its working