We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13643
    • 44 Posts
    Let’s suppose that I’m building a site for Joe the Architect. He wants a photo gallery of his work (naturally), but it has to be in a different spot on each of three different pages. Now, the way I understand it, the typical way to include a dynamic element like a photo gallery would be via a snippet call (or a chunk that contains such a call) - so far so good.

    The question is - where to put the snippet call or chunk? It has to be in different locations on different pages, so putting it in the template requires that I make a different template for each page, which seems like a bad idea.

    I could put it in with the content, but in addition to the fact that this "feels wrong", there is the problem of what happens when Joe decides he needs to edit some content on one of the pages, and accidentally overwrites the code that calls the gallery. In addition to the above, rich text editors like MCE like to put <p> tags and other markup on everything, including snippet and chunk calls, and I’m not sure what effect this might have.

    In sum, my problem is one of separating dynamic from static content, without experiencing template proliferation. Any suggestions?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There is nothing wrong with "template proliferation" if it seems the best way to attain a goal. You can minimize the effect by putting the main common sections (doctype, head, masthead and logo, footer, etc) in chunks so that they are all in one place for editing.

      Alternatively, you could use TVs for the gallery, and hide them from the editor users. They can be placed in the template where you want them, left empty for the default, and then the admin user can edit them to place the gallery snippet calls as appropriate for each resource.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 13643
        • 44 Posts
        You can minimize the effect by putting the main common sections (doctype, head, masthead and logo, footer, etc) in chunks so that they are all in one place for editing.

        Quite true - I actually have my main template down to about 40 lines, and I’m still trying to compress it further. This is certainly a viable option, I was just wondering if there is a better way.

        Alternatively, you could use TVs for the gallery, and hide them from the editor users. They can be placed in the template where you want them, left empty for the default, and then the admin user can edit them to place the gallery snippet calls as appropriate for each resource.

        The way I understand it, a template variable is designed to allow different content on each page for the same element (e.g., a sidebar, meta tags, etc.). Since we’re dealing here with an element that’s going to be the same on every page, the only benefit I can see to using a template variable vs. putting the snippet call directly in the template is that it enables the admin to control whether or not the element in question appears on a particular page at all without changing the template. I can’t see where using a TV gives the admin any more control over the positioning of the element, unless I’m misunderstanding something (very possible.)

        (BTW, you mention "hiding" the TV’s from the editor users. I see an option on the TV edit screen under access permissions to
        Select the Resource Groups that are allowed to modify the content or value of this Template Variable
        Trouble is, I can’t uncheck the box - any idea why this would be?)

        Back on the original topic, would it be correct to say that the structure (i.e., positional aspects) of the page should always be determined by the template? And that any variation in the structure of a particular page requires a separate template? I suppose that’s what I’m really asking.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If you have three different locations on three different pages (or groups of pages) where you want the galleries to appear, use three different TVs. You can put all three TV tags in the template, and since they are empty by default they won’t output anything except for the pages where you edited the relevant resource. And it’s easiest to hide TVs using ManagerManager, which hides a specified TV for users of a specified role.

          If you want some content, then a gallery, then some more content, use another Rich Text TV for the second block of content and let the editor use it. Then you’d have
          [*content*]
          [*galleryX*]
          [*AfterGallery*]

          Or to make it even more clear for the editor, hide the main content field with ManagerManager, and have yet another Rich Text TV:
          [*BeforeGallery*]
          [*GalleryX*]
          [*AfterGallery*]

          Or just rename the Content to Before Gallery or something using ManagerManager. There’s probably a dozen other ways to do it; this is MODx!
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 13643
            • 44 Posts
            Hmmm... I’m starting to think maybe I’m "under-driving" the template. I suppose it’s entirely possible to have TV’s for almost everything - DOCTYPE, stylesheet and script links, etc., and put chunks in as default values. That way, you can "tweak" the template for a particular page, without affecting all the others.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You can even use one TV with radio buttons or check boxes to choose which ones you want for a given resource.

              http://www.sottwell.com/tv-input-types.html
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org