We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: kongondo at Jul 24, 2009, 02:54 AM

    ps: we’re not bashing you at all....;)

    Right. I didn’t mean my post to sound so harsh (tough day). We certainly appreciate the contribution and it does sound very creative -- just not sure where it fits in. smiley
      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
      • 8109
      • 128 Posts
      Quote from: BobRay at Jul 24, 2009, 02:28 AM


      If one page requires a sidebar and another doesn’t, why not put the sidebar in one template and not in another? Or use sottwell’s suggestion and create a sidebar/no_sidebar TV with radio buttons and have it return a chunk name (one chunk with a sidebar and the other without a sidebar). If you put the code that goes in *all* templates into chunks, I think you accomplish the same thing a lot faster and easier and without a snippet.

      You’re absolutely free to design your site any way you want but please try to use MODx terminology correctly because new users are confused enough already. wink

      This is exactly what I’m trying to avoid: maintenance of multiple templates. If one template requires a sidebar, and the other doesn’t, and that’s the only difference between the two templates, then my snippet allows you to do just that. Sottwell’s solution requires that you create a VV that duplicates the information already available in the template name itself. In other words, if every page that uses/is assigned to a particular template requires something to appear on the page, then my snippet solves this without having to put a new and redundant TV on every one of those editor pages.

      Now, as for using ModX terminology correctly, I can’t see any way around this conundrum, as we have two uses for the word template. One is the html code that describes the page layout (what my snippet can modify) and the other is assigned to a document and to which TVs are associated (which my snippet checks to decide whether or not to insert a named chunk.

      Incidentally, you could just as easily use this snippet to insert specific header elements (css or javascript includes) as well as layout-related chunks.

        Revo 2.0.8-pl
        • 3749
        • 24,544 Posts
        Quote from: drwagner13 at Jul 24, 2009, 04:02 AM

        Now, as for using ModX terminology correctly, I can’t see any way around this conundrum, as we have two uses for the word template. One is the html code that describes the page layout (what my snippet can modify) and the other is assigned to a document and to which TVs are associated (which my snippet checks to decide whether or not to insert a named chunk.
        This is where I think you’re getting confused. In MODx, a template is not "the html code that describes the page layout." A template is a MODx object that is stored in the MODx database. It exists as a single row in the modx_site_templates table. There are other template-like things in MODx, but none of them can be correctly called "templates."

        If your goal is to have only one template to maintain, you can only have one template in the modx_site_content table. If you really need multiple templates (and many, many MODx sites use a single template even though they have pages with different layouts), the best way to reduce maintenance issues, IMO, is to put the code that is in every template into chunks (e.g. a header chunk, a footer chunk, a menu chunk, etc.). That way, the templates themselves almost never need editing.

        Just my $.02. smiley
          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
          • 8109
          • 128 Posts
          Not to totally devolve into semantics, but then what do you call the layout of a page (html and css), other than a template? We have two uses for the word in ModX, and that means ModX has co-opted the word and caused this confusion.

          Still, has anyone tried using the snippet? BobRay has summed up an important part of template writing, the use of chunks. My snippet extends this use of chunks to allow for template-specific placement of chunks.

          I’ll leave it as an exercise for the reader to figure out which use of the word template is meant in each instance above wink
            Revo 2.0.8-pl
            • 3749
            • 24,544 Posts
            Quote from: drwagner13 at Jul 27, 2009, 05:28 AM

            Not to totally devolve into semantics, but then what do you call the layout of a page (html and css), other than a template? We have two uses for the word in ModX, and that means ModX has co-opted the word and caused this confusion.

            Many CMS platforms have a specific use for the word "template" so MODx didn’t invent that. In DreamWeaver, for example, a template is an html file with special templating code in it to designate areas as editable or not. In practice, it’s a lot like a MODx template.

            In answer to your question, the only object that contains the layout instructions for a whole web page is a MODx template object. It’s the container object for every page displayed at a MODx site. You can certainly move pieces of layout code into chunks, snippets, plugins, template variables, etc. but they are all displayed and organized via the template. If you use the word "template" to refer to the layout code in all those elements, the word becomes useless, IMO.

            So I generally describe "the layout of a page (html and CSS)" using the terms "layout," "html," and "CSS." wink

            So far, people seem to have a pretty good idea what I mean.
              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
              • 30223
              • 1,010 Posts
              Lets leave the semantics discussion for another time. It’s not adding anything useful anymore.

              what I think drwagner13 is trying to accomplish is to compile the HTML LAYOUT for each of the MODx TEMPLATES from one source. The source in his case is stored in a chunk which, using his ifTemplate snippet, contains logic that decides what further chunks should be loaded based on the template id as stored in the database.

              So, all of his (modx) templates only contain
              {{mainChunk}}


              His mainChunk contains most of the html layout and some logic:
              <html>
              <head>
              if (template_id = 3 or 4) insert {{shoppingTrolleyCode}}
              </head>
              <body>
              <lots of stuff>
              if (template_id is 1 or 2 or 5) insert {{sideBar}} else insert {{numerousAdds}}
              </lots of stuff>
              </body>
              </html>
              


              Most of this has been discussed before. See http://modxcms.com/forums/index.php?topic=37155.0 including similar solutions such as a plugin http://modxcms.com/forums/index.php/topic,32493.0.html and a snippet version http://modxcms.com/forums/index.php/topic,30755.

              The only difference being that in this case decisions are made on the template id, which could possible just as easily be incorporated into the solutions listed here.

              I can see drwagner13’s problem but personally it’s not the soution that I’d use. As always it comes down to personal preference and the many ways you can do things in MODx..