We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50711
    • 5 Posts
    I've just started learning MODX and I got a question about using the same template(I have the same header and footer on all pages) for different resources and also specifying different TV's for each resource. Is there a way to do this or any other solutions to efficiently implement this?

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      The usual way, to have different TVs for different Resources, is with different Templates.

      If you want reuse parts of your template, put them into chunks, and put this chunks into your templates.

      Looks like that:

      [[$head]]
      [[$header]]
      [[*content]]
      [[$footer]]


      you can also put the whole template-code into one chunk and send some different placeholders to that chunk from your templates like

      [[$myTemplate? &contentchunk=`baseContent`]]
      


      [[$myTemplate? &contentchunk=`specialContent`]]
      


      and have in your template - chunk placeholders like that:

      [[$[[+contentchunk]]]]


      The baseContent - chunk could have:

      <div id="content">
      [[*content]]
      </div>


      you can inject different values into your template-chunk this way.

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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50711
        • 5 Posts
        Quote from: Bruno17 at Jul 08, 2015, 06:20 AM
        The usual way, to have different TVs for different Resources, is with different Templates.

        So to have different TV's for different resources, even though their template is the same, I have to create same templates with just different name? I understand the chunk part though. Thank you!
          • 4172
          • 5,888 Posts
          Yes, since Template-Variables are connected to Templates, not to resources.
          Only the Template-Variable-Values are connected to Resources.

          It is possible to hide some Template-Variables with form-customization, if you want so.
          But I would just use different Templates and have the reusable template-code in a chunk or divided in multiple chunks, if you prefer so.

          Another way is, to have the template code in a file and let all templates be static and point to the same file.

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

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50711
            • 5 Posts
            Quote from: Bruno17 at Jul 08, 2015, 06:54 AM

            Another way is, to have the template code in a file and let all templates be static and point to the same file.


            Is this way more efficient than having multiple templates? And how do I do it? Sorry for so many questions, and thank you for all your answers, they're really helpful.
            • discuss.answer
              • 4172
              • 5,888 Posts
              with a static template (see http://rtfm.modx.com/revolution/2.x/administering-your-site/upgrading-modx/upgrading-to-2.2.x#Upgradingto2.2.x-StaticElements)

              you will still need to have different templates for different TVs.
              You just have the template-code in a file instead of a chunk.

              If the one or the other is more efficient for you, depends on your personal taste and workflow.
              If you prefer to work with files directly, rather working in the backend, the static-elements-solution might be more efficient for you.

              But you need to clear the cache, each time, you made changes to the template-file, if you are working with files.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 50711
                • 5 Posts
                Ok, I got it. Thank you for your help!