We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36897
    • 11 Posts
    This is mostly a best practices question. I know with Modx there are so many ways to do a certain things, which I think is great. It gives you a lot of options on how to do something.

    I was wondering from experience, or just opinion, what you think the best way to use templates is?

    For example, let's say you have a 5 page website and each page has a different content setup, maybe a different layout. Is the best way to go about building the site to have a separate template for each page? And then have each of those templates pulling in chunks for elements that are reused or elements that are unique for that particular page.
    And then for like pages that are structurally similar you could get away with reusing the same template.
      • 3749
      • 24,544 Posts
      It's really a matter of personal taste more than anything. There are advantages to having a common template, but depending on how different the page layouts are, it can also cause a lot of annoyances.

      The complexity of the CSS/HTML is also a factor. If it's more complicated, using a single template causes more trouble because it becomes more difficult to change one page's layout without affecting the others.

        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
        • 40447
        • 165 Posts
        This question can not be answered the way you asked it, because, unlike other cms'es, the architecture of Modx is such that it stands out of the way of the developer. There is no Modx way. Actually there is only 1 way to answer your question. Find 4 or 5 websites on the web with a layout close to your needs/project. Then try to mimic these layouts with Modx using chunks, snippets, tv's, modx tags, api, etc. etc. After that you will know pretty well how to use them. I tried dozens of cms'es and always end up with Modx. [ed. note: sitecms last edited this post 13 years, 7 months ago.]
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In my case, it depends on my mood. If I'm in a whimsical mood, I'll use a single template, TVs to specify which layout .css file to use and form customization to show/hide TVs and other parts of the resource editing forms as appropriate.

          Usually, though, I find that three or four templates with the common parts broken out into chunks are more practical.

          There is a fascinating add-on that actually uses resources as a development IDE for Revo https://forums.modx.com/thread/77735/ro-ides-editor-and-framework-for-modx-revolution-2-2
            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
            • 4172
            • 5,888 Posts
            For example, let's say you have a 5 page website and each page has a different content setup, maybe a different layout.

            It really depends on what is the difference between them.

            Often you can use the same template and switch parts of them (which you have in chunks) by a listbox-TV: box A==[[$box_a]]||box B==[[$box_b]]||box C==[[$box_c]]

            or you can use MIGX to have the option for adding multiple boxes(chunks) and move them by drag/drop into the correct position.

            If you have 'functional pages' with no content but different functions (like a contact-page, galleries, news-listings) and same layouts you can put your snippet-tags into the content.
            Tip: disable richtext for pages like that before putting snippet-tags into it.

            If you need additional CSS/js on some pages there are also multiple ways to add them dynamically.
            There are for example these (seems undocumented) output-filters:
            'cssToHead' 'htmlToHead' 'htmlToBottom' 'jsToHead' 'jsToBottom'

            which can of course also be used in combination with a MIGX-TV for example.

            If you need completely different TV-sets in the manager you can use static-templates which point to the same template-file but have different TVs assigned to them.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              There are for example these (seems undocumented) output-filters:
              'cssToHead' 'htmlToHead' 'htmlToBottom' 'jsToHead' 'jsToBottom'

              Interesting. I didn't know those were there but they are. They would be great for adding quick JS effects like onclick() functions without having to create a new snippet just to inject the JS code.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Interesting, indeed.

                                        case 'toPlaceholder':
                                            $this->modx->toPlaceholder($m_val,$output);
                                            break;
                                        case 'cssToHead':
                                            $this->modx->regClientCSS($output);
                                            break;
                                        case 'htmlToHead':
                                            $this->modx->regClientStartupHTMLBlock($output);
                                            break;
                                        case 'htmlToBottom':
                                            $this->modx->regClientHTMLBlock($output);
                                            break;
                                        case 'jsToHead':
                                            if (empty($m_val)) $m_val = false;
                                            $this->modx->regClientStartupScript($output,$m_val);
                                            break;
                                        case 'jsToBottom':
                                            if (empty($m_val)) $m_val = false;
                                            $this->modx->regClientScript($output,$m_val);
                                            break;
                
                  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
                  • 4172
                  • 5,888 Posts
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 40045
                    • 534 Posts
                    Wow, nice find Bruno, thanks (and susan too for the respective code)!

                    I added them to the docs: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29

                    but description and also usage are just guessed, if somebody could confirm description and usage I'd love to change them =D...(of even better, if you can change, change!)
                      • 3749
                      • 24,544 Posts
                      I think the usage would more likely be via a chunk rather than a TV, but I'm not sure.

                      As far as the result, you could try them and do a "view source," but you could also just look at the docs for the MODX methods they call in Susan's post above.
                        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