We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Basic question, I know, but what is the difference between
    [[+tv.name]]
    and
    [[*name]]
    ? When would you use each? [ed. note: waizen last edited this post 14 years, 1 month ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The + is a placeholder. It is primarily used in listing snippets which have a mini-template that they apply to each resource in their list. The placeholder will be populated with the TV's value for the list item the snippet is processing.

      The * is the TV indicator, it will ALWAYS return the TV's value for the resource being viewed. In the case of a resource with a getResources or other listing snippet, it will be the value for the resource that has the snippet call. So a * TV in a getResource's mini-tpl would always return the same value, that for the page being viewed, and not for the resource being processed for the list.
        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
        • 39932
        • 483 Posts
        For further clarification:

        The * applies to any field of the current Resource. TVs are treated as fields of the Resource and are accessed in the same way, but you may also use *pagetitle or *alias, and this is a field, not a TV. In contrast, a TV wiht the name "joe" will be accessed as *joe.

        The + is always a placeholder. Placeholders are set by many things, automatically and manually. If you send a Chunk any parameters whatsoever, these each go into parameters. For instance,

            [[$ChunkName?
                ¶m1=`value1`
                ¶m2=`value2`
            ]]
        


        will generate placeholders named param1 and param2. These are accessed by

            [[+param1]]
            [[+param2]]
        


        Doing this allows you to not worry about conflict between placeholders, fields, settings, etc. (The prefix char [ *, +, ++, $ ] helps to distinguish. Listing Snippets, as @sottwell stated, are the most common use of this, but placeholders may be set by and for a lot of reasons. Like in the example above, these are set my MODx when you make the call to the Chunk.

        In a Snippet, you may make a placeholder yourself with this code:

            $modx->setPlaceholder('name', 'value');
        


        Then it may be accessed anywhere by using

            [[+name]]
        
          Website: Extended Dialog Development Blog: on Extended Dialog
          Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
          Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

          Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
          • 31902
          • 342 Posts
          Thanks for the clarification, folks.

          The reason I'm asking, and maybe you can tell me what is going on from an actual case, is that I've got a listing of items that are being drawn from a container. I'm using the getResources component.

          The call I'm using looks like this:
          [[!getResourcesTag?
            &elementClass=`modSnippet`
            &element=`getResources`
            &tpl=`events_page_full_listings-tpl`
            &parents=`6`
            &limit=`50`
            &includeContent=`1`
            &includeTVs=`1`  &includeTVList=`home_events_image,events_intro,event_date,event_date_end,optional_event_date`
            &showHidden=`1`
            &hideContainers=`1`
            &cache=`0`
            &pageVarKey=`page`
            &sortbyTV=`event_date`
            &sortdirTV=`ASC`
          ]]


          ...and the contents of the events_page_full_listings-tpl looks like this:

          <div id="events_page_full_listings_container">
          
          <div id="events_page_full_listings_image">
          <a href="[[~[[+id]]]]"><img src="[[+tv.home_events_image]]" /></a>
          </div><!-- events_page_full_listings_image -->
          
          <div id="events_page_full_listings">
          <h2><a href="[[~[[+id]]]]" class="articles_title">[[+pagetitle]]</a></h2>
          <p>
          <strong>[[+tv.optional_event_date]]</strong>
          
          [[+tv.events_intro:limit=`265`]]...
          
          <span class="links">
          <a href="[[~[[+id]]]]" class="readmore">Click for more details...</a></span>
          </span></p>
          </div><!-- events_page_full_listings -->
          <div style="clear: both;"></div>
          
          </div><!-- events_page_full_listings_container -->


          Notice the +tv.home_events_image and +tv.optional_event_date TVs I created and added within the tpl. They won't work if it is coded as *home_events_image or *optional_event_date. In this case, they only work with the +tv. in front of it.

          What obvious thing am I missing? It's not a problem...I just want to understand because I'm sure it's going to bite me someday in some other case.

          Thanks. [ed. note: waizen last edited this post 14 years, 1 month ago.]
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Most likely the page the getResourcesTag snippet is on (the "current" page you're looking at) doesn't have that TV. But the resources that getResourcesTag is processing does, so the placeholder in its tpl works.
              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
              • 31902
              • 342 Posts
              Okay, so is it fair to say that if a TV is created on Page 'A' (has its own template with TVs associated with it) and I place that same TV on another page called Page 'B' (with a different template, for instance), then the call on Page 'B' needs the +tv.? Because it's going "intra-template", so to speak? Did I just make sense?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I don't think page B will see it at all.

                In a tpl, it depends on the snippet being used. Some need to have TVs prefixed with something like tv.name, some don't. The tpl is nothing to do with the page you're looking at, it is only used by the snippet to format the output it gets when it loops through the resources you told it to fetch (like parents in getResources or startId in Wayfinder).
                  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
                  • 31902
                  • 342 Posts
                  So, for instance, if I then have that same TV, as created within Page A, and want to place it in Page B (in this case, no template or anything...just a straight call), I would then just call it by way of *name, right? Don't even bother with the +tv. thing in front of the name?

                  As I write this, I'm actually wrestling with something in that a TV I created in a page is being called on another page, but for whatever reason, is not appearing, whether with +tv. or asterisks. I'm sure my problem is something beyond the scope of this thread but for some reason, on the same page, the TV appears on one place using the +tv. prefix and in another place on the same page, it is not appearing, although the code is a straight copy/paste.

                  The page won't exist for long, but you can see what I'm dealing with here today:

                  http://108.160.154.121/~amff/test.html


                  The bottom and side column are being generated with the code I outlined earlier and I want to add a 'Featured Events' section on top, which is getting the code by other ways...not through the code mentioned above. That code is coming from the same place the events on the home page are getting theirs (successfully), as seen here: http://108.160.154.121/~amff/index.php. But, the TVs up there are not appearing, whether I use the +tv. or *. [ed. note: waizen last edited this post 14 years, 1 month ago.]
                    • 39932
                    • 483 Posts
                    Okay, so is it fair to say that if a TV is created on Page 'A' (has its own template with TVs associated with it) and I place that same TV on another page called Page 'B' (with a different template, for instance), then the call on Page 'B' needs the +tv.?

                    You would be correct. Page B would need the +tv. However...

                    I don't think page B will see it at all.

                    This is correct. Page B would have to seek the tv from Page A via a Snippet or Plugin.
                      Website: Extended Dialog Development Blog: on Extended Dialog
                      Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                      Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                      Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                      • 31902
                      • 342 Posts
                      So, if I want to add a TV that originates on Page A and also call it up across other pages, I would need to go through a snippet or plugin? I could swear I've done it before without needing to go through that.

                      In the case of today's project, the TVs are originating from the home page template (adding the info through the home page backend) but also need them to appear in the other page. Can someone suggest how to make those TVs call up in the other page as well? Would think this is a basic thing but I've been pounding my head on this since yesterday.