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
    This is an auto-generated support/comment thread for automaticTpl.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Automate the template of your documents. Now there is no need to worry about the template field.

    Eg:

    / (root)
    programs
      myprogram1
        mysubprogram11
      myprogram2
        mysubprogram2
    sub-subprogram
    Note:  Each level has a diffrent template

    Lets say you want to automate the assignment of the templates for the myprogram and mysubprogram levels

    I solved this by creating a TV for the programs template called automaticTpl that works with the automaticTpl plugin. You need to specify the id of the TV to the plugin.

    Inside the tv you would specify the template id the manager has to set automatically Eg: 5,7. This means myprogram level will use template 5 and mysubprogram template 7

    You can use the automaticTpl TV for any container. In case a template id is not detected Inherit Parent Template plugin will kick in(IF INSTALLED)(Eg: sub-subprogram)


    TODO: Change the template on document move.
    Use suggestions from http://modxcms.com/forums/index.php/topic,28186.msg171255.html#msg171255
    Make it configurable if this is wanted


      • 27749
      • 53 Posts
      Hi,

      so if I get this right - this should change the template according to the parent the current document is placed in?

      - Created the TV, assigned it to templates
      - I installed the plugin, configured id with the TV id
      - Set the template ID in the TV of the parent document
      - Now when I create or move a document into this folder - nothing happens - the default template stays set :-(

      Maybe its something different this plugin should do or I am looking for, but any help would be apreciated.
      THX
      Smiley smiley

        • 5340
        • 1,624 Posts
        I do not think it works with move document. It works when you Create a document.
        But is a nice idea. Unfortunately there is no OnDocFormMove. maybe I’ll find something

        As for you problems I have no clue why it does not work

        Maybe you can post a detailed description.
          • 31533
          • 8 Posts
          i got the same problem as in smiley’s post. i followed instruction, checked everything twice, and make sure that Inherit Parent Template plugin is called before automaticTpl. Then i go to manager, click on my container, click tab "View children", then click on child document creation button. And template doesn’t changed. It’s same as parent have. No moving, just straightforward creation.

          What to do?
            • 31533
            • 8 Posts
            I’m terribly sorry! The problem (mine and smiley’s) in that we didn’t delete begin/end PHP tags. Personally i was confused by beginning of original automaticTpl code:
            <? 
             /* Automatic template
            

            That was my bad. Now everything works ok. Thanks a lot for this very useful plugin!

              • 5340
              • 1,624 Posts
              I’m happy it works and you like it.

              Let me know how you would improve it

                • 4058
                • 17 Posts
                Could you please provide better installation instructions. What you have currently provided may make sense to you, but it lacks the detail to up and go with it.

                Thanks.
                  • 5340
                  • 1,624 Posts
                  This plugin works with a TV. Unless you understand TVs and plugins, I can only help you personally.
                  Please put you question here and I’ll answer the best I can.

                  You can improve the instruction yourself by creating a new version or send them to me and I will do it for you.

                    • 4058
                    • 17 Posts
                    Thanks for the quick reply.

                    I will try not to be harsh, as I am generally just very discouraged. The main problem I have is that people providing new functionality and content are severely holding back the potential of MODx by not being (to the minimum) granular with their installation instructions. I have spent more time looking for alternative installation instructions for a number of great functionality such as yours, than actually working with the functionality and modifying it to our needs.

                    So this is what I would suggest to you and any others who would read this. Please, provide step-by-step instructions to install your functionality so that there is little chance someone could do it wrong.

                    Additionally, because I am just sick of this being an issue, (and significantly slowing up my projects, rather than speeding up production as it obviously has the ability to do) I am going to be slowly providing instructions for installing all extras so that a friggin 7 year old who is retarded could walk through the instructions and get it to work. I will setup a web site soon so that they will neatly be in one place.

                    The biggest issue is just about everyone on this forum is leaving out details they assume are mundane. So then people have problems, come back here and post it and then finally the correct clarification is given. This clutters this forum, degrades the integrity of all the information here, and inevitably ruins the value of MODx.

                    So, please excuse my rant as I’m quite ticked off. I would like to collaborate with you so that we can provide other users the proper detailed instructions on how to get this to function properly and won’t need to come back here because they couldn’t get it to work.

                    Here is what I have:

                    automaticTpl

                    Installation:

                    1) Download the plugin from http://modxcms.com/extras/package/?package=34
                    2) Create a new Template Variable with the following information:
                    a) Variable Name: automaticTpl
                    b) Caption: Leave blank (MODx will automatically set this the same as the Variable Name after save.)
                    c) Description: If desired.
                    d) Input Type: Text
                    e) Input Option Values: huh
                    f) Default Value: huh (A newbie at this point would be lost even though this is likely blank or has the value {{}}. It needs to be said it is blank if it is so. Sometimes the mundane info is more important than the vital information.)
                    g) Widget: Don’t change, leave blank.
                    h) Sort Order: Don’t change unless desired.

                    i) Template Access: (Which template should I specifically be choosing here? The template that my parent document is using, all templates that will be involved in the automatic selection, or just the template that will be automatically selected when a child document is created?)
                    j) Access Permissions: Anything important about how this setting influences the functionality? I assume it doesn’t, however does a newbie understand this?

                    3) Take note of the id of the automaticTpl Template Variable from either the Template Variable Resource List or from your database table modx_site_tmplvars.

                    4) Create a new plugin with the following information:
                    a) Plugin Name: automaticTpl
                    b) Description: If Desired
                    c) Plugin Disabled: Leave Unchecked
                    d) Plugin code (php): Copy & paste the code from the automaticTpl.php file that you downloaded in the first step.
                    5) Go into the System Events tab and find OnDocFormPrerender and check it on.
                    6) Go into the Configuration tab and paste the following code: &automaticTplTvID=automaticTpl TV ID;text;
                    7) Click anywhere outside the textbox, this will dynamically generate a new parameter field.
                    8) Input the ID of the Template Variable you took note of before.
                    9) Go back to the main Plugins Resource List page and click on ’Edit Plugin Execution Order by Event’. Ensure that ’automaticTpl’ is sorted BELOW ’Inherit Parent Template’. If not, change it to be so. (What about any others like ManagerManager? Any conflicts?)
                    9) Create your new document and verify that the correct template is automatically assigned.


                    Ok, I think that is a start. I have a few additional questions. Can I make child documents that are located within different parent documents set different templates and what do I need to do in order to do that? Second, how does the Template Variable understand the difference between different sets of parent & child document template settings?

                    Currently I have ’9,7’ (my template IDs) set as my Input Options Values and have then selected both of these in my template access. What am I doing incorrectly?

                    Finally, I apologize for the long-winded post. I feel a little better..

                    Can you copy & paste my installation instructions and add/edit as needed?

                    Thanks.



                      • 5340
                      • 1,624 Posts
                      Hi brettdusek,

                      Thx for your input, I’ll update the instruction ASAP.

                      As for you questions I’m not sure I understand what you but here goes:

                      Can I make child documents that are located within different parent documents set different templates and what do I need to do in order to do that?

                      In your modx configuration you can specify the default template for the website. automaticTpl extends this to containers. So in order to use automaticTpl you need containers. In your root folder all the containers/documents will be created using the default modx template. If you want different templates in the same container( / is a container to, but the default template is setup in the modx configuration) you need to set them up yourself.

                      Here’s an example. In () is the template id
                      where there is an automaticTpl it means that the automaticTpl TV is associated with the template

                      /
                      container1 (modx default template) - automaticTpl=12,14,16
                      - container11 (12) - automaticTpl = 200
                      - - document111 (200)
                      - document12 (12)
                      - container13 (12)
                      - - document131 (14)
                      - - container132 (14) - automaticTpl=17
                      - - - document1321 (17)
                      - - - document1322 (17)
                      - - - document1323 (17)

                      As you can see document111 is not created with the template id 14 but 200 because the plugin looks for the first automaticTpl in the structure.
                      The same can be said about document1321

                      If I understood your question correctly the answer is YES.

                      how does the Template Variable understand the difference between different sets of parent & child document template settings?

                      The parent that has an automaticTpl value will not be influeced by that value. But the child will be created using the template id from the automaticTpl TV.

                      parent - automaticTpl = 2,4,6
                      the first child will be created using the template id 2
                      the child of the first child will be created using the template id 4
                      and so on...

                      If I did not answer your questions please be a bit more specific or maybe somebody else can give you a better explanation.


                      What about any others like ManagerManager? Any conflicts?

                      I am not aware of any conflicts. If you find one please let me know.