We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34459
    • 134 Posts
    I've got the book and read that but it didn’t change anything.
    As far as I’ve read throughout the forum everybody wrote that it’s not good to use many templates. As I look at my first projects, I’ve used nearly 1 template for one resource. As this method is time consuming and not very efficient I was trying to restructure some of my pages to use 1 or 2 templates for different resources with different tv’s. I am aware that I can do some part of “client-proofing” through ACL but it’s way better to hide(form custom.) then to disable(ACL),(especially if you encounter “I need to know everything” clients” ), besides the fact that as an administrator I want to see only tv’s which are connected to a specific resources and not all of them at once. Therefor there must be a way to be more efficient or I don’t understand the concept of modx.
      Check out blackflow.pl
      • 4172
      • 5,888 Posts
      Using different Templates for different TV-Sets is the easiest and best way to assign TVs to resources.
      Split your Templates into chunks (haed, header, content, sidebar, footer)
      This way you can reuse them on different templates.
      Its also possible to set placeholders into this chunks and add different properties for different templates, if this is needed

      [[$content? &box1=`getResources` &box2=`gallery` &box3=``]]


      and in your content-chunk:

      <div id="contentbox">
      [[$[[+box1]]]]
      [[$[[+box2]]]]
      [[$[[+box3]]]]
      </div>


      other parts can be switched on and off by checkboxTVs.
      Also MIGX can be used creativly to add and sort parts.
      The possibilities are nearly endless.

      To use different templates doesn't mean to duplicate your code, when you put the code itself into reusable chunks.
      Templates are a great way to organize your different TV-Sets.


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19369
        • 1,098 Posts
        @blackflow, I'd follow bruno example, you need a template for each page that requires different template variables. With a smart use of chunks, you can actually have all templates with the same code, the only thing that will change will be the tvs assigned to them.

        Here is an example of my templates (all with same code):
        [[$head]]
        <body>
        
        <!-- [Container] -->
        <div id="container">
        	
        [[$header]]	
        
        	<!-- [Content] -->
        	<div id="content">
        		  
        		<!-- [Text] -->
        		<div id="text">
        					
        [[$content-template-[ [*template] ]]]		
        				
        		</div>
        		<!-- [/End Text] -->		
        
        [[$sidebar]]
        	
        	</div>
        	<!-- [/End Content] -->
        	
        </div> 
        <!-- [/End Container] -->
        
        [[$footer]]
        
        </body>
        </html>


        The "key" here is the code "[[$content-template-[ [*template] ]]]", because with that you can basically use a different chunk for every template, but the code for each template will be the same (there are many other ways of doing this, you just need to find "your way").

        If one page has differences which are not related to Tvs, don't make a template, use the If or the andif snippet, or output modifiers. Combine them with getResourceField if you need to set up global settings for the whole website.

        You can also use a snippet like this that returns the tree depth, which, combined with the if, andif and output modifier, can allow you to use even less templates. [ed. note: microcipcip last edited this post 14 years, 7 months ago.]
          • 16899
          • 284 Posts
          Excelent way to do that!!! I´m doing really similar but a bit more simplistic!!!! smiley

          [[$head]]
          		
          		[[$header]]
          
          		[[$banner-area]]	
          		
          		[[$template-name]]
          		
          		[[$footer]]
          


          The indentation of each chunk it´s related on the html block inside of each chunk ( i like to have all the code well formatted).

          The key in my case is the chunk
          [[$template-name]]
          ... the diference between all the templates will be here because this chunk will be have for example full width template, 2 col template, and so on... based on 3 Variables - Left Column, Right Column, Full Width.

          For example for a 2 cols template Chunk you could have the code:
          
          <div id="content">
          
          <div class="grid-3">
          [[*left-column]]
          </div>
          
          <div class="grid-9">
          [[*right-column]]
          </div>
          
          </div>
          
          
            • 34459
            • 134 Posts
            ok I got by for some time but there is one thing I don’t understand or I am missing...When you use one template, you must assign every tv to a template or it won’t show...right? so you still always get every tv assigned to that template = visible in the tv resource tab while editing your resources?
            The thing that bugs me most, is that I can’t hide tv’s assigned to a page and show the in the next using one template. It would be very easy to do that with form customization by restricting tv’s to pages instead of templates, but it dosent work with tv’s…
              Check out blackflow.pl
              • 19369
              • 1,098 Posts
              Quote from: blackflow at May 16, 2012, 12:20 PM
              ok I got by for some time but there is one thing I don’t understand or I am missing...When you use one template, you must assign every tv to a template or it won’t show...right?
              Yes, you're right.
              so you still always get every tv assigned to that template = visible in the tv resource tab while editing your resources?
              Yes.

              The thing that bugs me most, is that I can’t hide tv’s assigned to a page and show the in the next using one template. It would be very easy to do that with form customization by restricting tv’s to pages instead of templates, but it dosent work with tv’s…
              Actually it is not that easy in this way, if you allow the user to add more pages, how do you tell MODX what TVs are assigned to that page? Only with a different template you can do this.

              If your problem is that you're adding too many TVs to a template, try a more dynamic approach, for example with MIGX.

              If your problem is that you want different TVs for different levels of depth of the website, try this plugin: https://forums.modx.com/thread/50864/inherit-selected-template-in-revolution?page=3#dis-post-407733.
                • 34459
                • 134 Posts
                So why we assign tv's to templates instead of resources? wouldn't be better to assign them to pages?
                The only reason why I make more than one template is to make modx idiot proof for clients( It gets confusing if in the contact page you get tv's from home).
                Anyway thanks for clarification smiley
                  Check out blackflow.pl
                  • 19369
                  • 1,098 Posts
                  Quote from: blackflow at May 16, 2012, 02:04 PM
                  So why we assign tv's to templates instead of resources? wouldn't be better to assign them to pages?
                  What do you mean exactly by "pages"? The point is, when the user create a Resource, MODX doesn't know what TVs assign to it if there is no template. If you assign TVs to a specific Resource (for example using the ID), and the user delete the Resource (by mistake or for whatever reason) you will lose your configuration.
                    • 34459
                    • 134 Posts
                    yes but it looks like templates are treated like structures for chunks. Imagine that instead of assigning tv’s to templates you could chose them in the page tabs- tv’s you want to be visble. Better yet you could group tv’s in categorys and select a whole category to be visible or not. Maybe I am wrong but it sound more logical to use tv’s for pages then templates.
                      Check out blackflow.pl
                      • 19369
                      • 1,098 Posts
                      I understand your point, basically you'd like the superAdmin to add TVs at will, without restricting them to a specific Template. Then in the Template this TVs will not appear if they're not visible in the Resource.

                      This could work for some kind of websites (mainly small websites where you can control what the user is going to do). I still prefer to use Templates because when the user delete the resource, or when he adds a new Resource, I would have to work on the configuration again.