We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35145
    • 3 Posts
    Hey so I’ve been using modx for years now but only recently grasped how awesome template variables are and how you can use them for a lot of functionality that I would usually search for a mod to do.

    But I’ve got a tiddly problem.

    Over the course of developing a site I ended up creating template variables assigned to different templates depending on what those documents are used for.

    The problem is that all of these templates have had to have the actual site template included in them with only slight changes around the content. So I end up almost defeating the point of the site template.

    So I feel like I need two levels of templates or the ability to assign TV’s to document groups rather than templates. So I can have my one site template and still filter TV’s to specific document groups.

    I’m not even sure if that makes sense, but hopefully someone can correct me on my usage, cos knowing modx theres a right way to do it.
      • 3749
      • 24,544 Posts
      It sounds like you could get by with just one or two templates and some creative use of TVs. The same template can look very different on different pages if you use TVs to include optional content and to specify different CSS files for different pages.

      You do know you can connect the same TV to multiple templates, right?
        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
        • 35145
        • 3 Posts
        Btw im using latest version of evolution.

        Yea but this is what ive got:

        Directory (with categories then directory items)
        And two different types of blogs
        An asortment of static pages.

        So i need a different set of tvs for:
        Categories
        Items
        Blog1
        Blog2
        Standard pages

        This also needs to be userfriendly for the sites owner so cant just have a huge set of tvs when editing every resource.

        Hope that clears up what im asking a bit more
          • 4310
          • 2,310 Posts
          You can put all the common bits of html into chunks, then use the chunks in your templates e.g.
          {{doctype}}
          
          <head>
          
          {{head}}
          
          {{js-scripts}}
              
          </head>
          
          <body id="products">
              <div id="wrapper">
             
              
                      {{header}}
                          
                  <div id="contentAll">
                  
                      <div id="titlePanel">
                          <h1>[!Breadcrumbs!]</h1>
                      </div><!-- .titlePanel -->
                      
                      [[Wayfinder? &config=`product-sub`]]
                      [!Wayfinder? &config=`product-show-me` &excludeDocs=`[[UltimateParent? &topLevel=`2`]]`!]
                          
                             
                  <div id="productPic">
                          [*PageImage*]
                      </div><!-- .productPic -->
                          <div id="contentProduct"><!-- contentMain -->
                            
                      
                      [*content*] 
                      
                          </div><!-- .contentMain -->
                          
                          <div id="subPanelRight">
                          
                              {{Reviews}}
                          </div><!-- .subPanelRight -->
                          
                          </div><!-- .contentAll -->
                  
                      <div id="footerAll">
                                     
                          <div id="footerPlus">
                          
                          {{footer-plus}}
                                  
                          </div><!-- .footerPlus -->
                      </div><!-- .footerAll -->
                      
                      <div id="siteCredit">
                          
                          {{site-credits}}
                          
                      </div><!-- .siteCredit -->
                  
                  </div><!-- .Main Wrapper -->
                     
                      
           {{stat-counter}}   
           
              </body>
          </html>
            • 12372
            • 44 Posts
            jessewheeler I think your post makes perfect sense, and I (as I imagine many will) have been the same. It’s sort of education, as you get to know MODX and as you work out your own preferences.

            I’m merging 3 MODXs, and that’s a mixture of someone else’s work and a mixture of my own work from when I first learned the system. I’m changing a lot of things now, which is due to me preferring to do stuff differently to the other person and also just improving on what I did a year ago.

            I think the balance is how much do you reuse stuff. If you end up with too many chunks and TVs etc. then I think it can get harder to edit a page because you forget where you’ve stored the stuff you want. Conversely you end up where you’re at - loads of templates which makes editing harder.

            bunk58’s example is closest to how I use mine and I think is an excellent example on what to aim for. I have about four different page templates still, but that’s not too hard to manage.

              • 35145
              • 3 Posts
              Thanks for that help! was good to know I’m not doing anything wrong.

              But I think I have figured out an even better solution... so let me know if this is helpful or why it might not work as well as I think it does.

              I switched to using Rev to try this out since thats what I should use going forward.

              I made all my templates just have the following call:
              [[!getResources? &resources=`[[*id]]` &includeTVs=`1` &tpl=`BaseTemplate`]]

              So this means I’m using a chunk for my main site template and just using getResources to output the whole thing. Essentially now chunks become templates and templates become document groups.

              Does that make sense?

              Haven’t tested this extensively yet, and would be good to know if anyone thinks there could be flaws in this.