We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1887
    • 50 Posts
    Hello hello

    Can I please have your suggestions for how to populate two columns with content without having to have a unique template for each page that differs?

    I landed up using [*content*] for the left hand column and [*introtext*] for the right column (which contains a chunk if there is a lot of content) which works great, but is there a better method?

    James
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can use a TV for that.
        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
        • 7231
        • 4,205 Posts
        Yes, a TV or Template Variable is the way to go. Here is a good discussion of how they work from a users point of view: http://modxcms.com/forums/index.php/topic,9989.msg68521.html#msg68521

        And here are the official docs on the subject: http://modxcms.com/template-variables.html
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 1887
          • 50 Posts
          I am getting lost in this wonderful flexibility.

          Assume I have a template, which looks like:

          <div class="left>
          [*leftcontent*]
          <div>
          <div class="right">
          [*rightcontent*]
          <div>

          How would TV’s help? I understand that they can be set to different values but I am missing the link between that and having one simple template that allows user definable content in each column. How do I, for example, display different content in the rightcolumn in [*rightcontent*] per page?

          TIA

          James

            • 7804
            • 80 Posts
            again, this is accomplished using a template variable.

            first of all, if your left column is your main content, then you should use [*content*] there. all document-specific template variables are listed here:

            http://modxcms.com/document-tvs.html

            if you do not use [*content*] somewhere in your template, you’re basically cutting yourself off of many of the features of MODx and undermining its functionality.

            so, let’s say your left column content is your main content. as i said before, use [*content*] there, as that variable will be populated with the HTML code you use in the "Document Content" for each page on the back end of MODx.

            then you would need to create a template variable that functions just like [*content*]. the only difference is that it is customized by you, and not part of the core of document-specific variables. it works exactly the same way, though.

            so, on the backend, go to Resources -> Manage Resources, then click the "Template Variables" tab. select "New Template Variable" and give it an appropriate name like "rightColContent". give it a caption and description. if you would like a blank text area to paste in raw HTML content on a page-by-page basis, select "textarea" or "richtext" as the input type. if you have default right-column content you’d like to include, paste it in "default value".

            (perhaps you only have three or four different "chunks" of right-column content that you want to use interchangeably on your site. in other words, pages in one area of your site will have the exact same right-column content, while pages in another area will have different content, even though within that area it’s all the same. in this case, i would recommend making each area’s right column content a separate chunk, and then set up your template variable to select these chunks on a page-by-page basis with a dropdown box or radio buttons. that way if you want to change the right-column content for just one area, you would only need to change the chunk as opposed to every single page within that area.)

            finally, assign the template variable to the template you’re using. then edit the template, and where your right-column content should be, include the [*rightColContent*] call. edit any page in your site and scroll down beneath the "Document Content" area to see your "rightColContent" textarea for inputting right column content.

            this is a very simplified way of doing what you’re asking. please make sure you read over the tutorial on creating template variables to fully understand the functionality and power of tv’s.
              • 1887
              • 50 Posts
              The bit I was missing in my mind was that the TV would be added to the manager form just like the existing content variable.

              Now all makes sense and gives a lot of control -- many thanks for explaining it.