We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14431
    • 65 Posts
    Please forgive me... I really have tried... Read the documentation, faq, and tutorials (much of which added to rather than relieved my confusion)... done a bunch of forum searches... I just don’t get Template Variables. I think I’ve groked chuncks and snippets but TVs are completely eluding me.

    How have the rest of you managed to figure this out? Is there a rosetta stone somewhere that I have just managed to avoid so far? Do I need to resort to trial and error? Is it obvious and I’m just stupid (most likely :’()

    Any help would be appreciated but most appreciated if given in plain, non-MODx, language.

    Thanks in advance!
    joe

    [SOLVED]... see my later post.
      • 25663 MODX Staff
      • 12,272 Posts
      TVs are nothing more than extra custom content fields. Where you’d put [*content*] in your template, you’d also similarly put your [*custom-tv-of-your-name-choosing*]. TVs give you extra formatting options though, and the power of @BINDINGS. Skip the advanced stuff and just stick with the basics for now. wink
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 727
        • 502 Posts
        TVs are simply values that you can use for pages based on specific templates.

        For example suppose you created the template "location", which you use to display pages that describe locations. You could create a template variable called "address" and associate it with the location template. Next suppose you created a new page using the location template called "White House". When editing that page you can also enter the address "1600 Pennsylvania Avenue" into the address template variable.

        Ok, so far so good. You can then edit the location template and add:

        <div id="locaddress">[*address*}</div>


        to automatically display the address for each location. In addition you can access the template variable values from snippets, allowing dynamic usage of the data. For example you could write a snippet called "map" that takes the address from the template variable and displays a Google map centered on the location.

        I hope this helps.

        Andy
          • 14431
          • 65 Posts
          Thanks ajayre & rthrash
          I really enjoyed the fact that both of you began your explanations with "TVs are simply..." and "TVs are nothing more than...". I’m looking forward to the time when it all clicks for me.
          I really do appreciate the explanations you have given!
          joe
            • 14431
            • 65 Posts
            Ok, I get it now, at least the fundamentals
            It would be most helpful to add something to either the Editing and Creating Documents section of the documentation, the wiki, or FAQ regarding TVs.

            For instance...
            Each editable characteristic of your document is captured and stored in what is called a Template Variable or TV for short. For instance, the standard content field that you edit is stored in a Template Variable called [*content*] and the page Title is stored in a Template Variable called [*pagetitle*].
            In addition to the standard editable page attributes and content, the site developer may define a wide variety of custom elements. The developer can define the editing mechanism (like Rich Text), default content, and the display widgit (like option buttons) that will be used. These custom elements, that are associated with a specific set of templates are also stored in Template Variables.
            When you are creating or editing a document that has one or more associated custom Template Variable defined, you will be presented with the associated editing mechanism for each of those TVs.
            A specific example might help...
            Let’s say that the developer has defined an element (Template Variable) that is intended for you, the editor, to capture a Thought-For-The-Day. So, a custom Template Variable has been defined called [*myTFTD*]. The developer specified that the Thought-For-The-Day should be displayed as text and that the editor should be a Rich Text Editor. So, now when you go to edit your page, not only will you be presented with the ability to edit the standard attributes and content, you will also be presented with another rich text edit section that is specifically for sharing your wisdom!
            What ever you enter into that Thought-For-The-Day element in the editing process will be stored in the [*myTFTD*] template variable. This variable can be placed (or not) anywhere in either the template (where spcial positioning and formatting can be applied) or directly in your content section and it will display the contents that you entered. Placing the TV in the document is as simple as putting the name of the variable [*myTFTD*] where you want the text (or whatever widgit was defined by the devloper) to show up.

            This is just the most fundamental description and use of Template Variables. Programatic access to these variables as well as the wide variety of types, editors, display widgits and parametric definitions allows a broad universe of applications.
              • 12652
              • 228 Posts
              Put that boy on the doc team wink

              That’s the kind of info I think we need more of, especially for those of us who haven’t been living and breathing MODx for months and who do not have any or much of a php/mysql background but more of a XHTML/CSS background.

              All in all, I think the information is great and better than you might find elsewhere, but often a more practical, concrete example/tutorial would make all the difference in the world between "wow, cool... not really sure what it does or how to do it, but it sure sounds cool," and "now I get it and can think of 10 places to use it right now and now I know how to put it to use."
                | Identity Developments delivers SEO focused web design and web presence services
                - it&#39;s not about websites, it&#39;s about your identity. |
                • 25663 MODX Staff
                • 12,272 Posts
                Except that the metadata (pagetitle, show in menu, etc.) and content aren’t TVs. That won’t happen until 1.0... but it is a good explanation that can be molded into absolutely correct info wink
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 14431
                  • 65 Posts
                  Quote from: rthrash at Oct 17, 2006, 11:01 AM

                  Except that the metadata (pagetitle, show in menu, etc.) and content aren’t TVs. That won’t happen until 1.0... but it is a good explanation that can be molded into absolutely correct info wink

                  I guess http://modxcms.com/document-tvs.html is what threw me off base... it seems to indicate that both pagetitle and content are template variables... after all, the title of the page is "Document-Specific Template Variables". And listed there are both "pagetitle" and "content"... seemed pretty unambiguous to the untrained eye rolleyes

                  joe
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Joe I think you explanation was absolutely wonderful, and that it should be used (with only a slight bit of factual editing) for helping folks "get" MODx.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 14431
                      • 65 Posts
                      Quote from: rthrash at Oct 17, 2006, 04:49 PM

                      Joe I think you explanation was absolutely wonderful, and that it should be used (with only a slight bit of factual editing) for helping folks "get" MODx.
                      If you can tell me what needs editing I’ll modify my post so as not to mislead anyone.
                      joe