We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    I have 2 Chunks (call them A and B). Each Chunk is used in a different Resource/Page (call them 1 and 2). Each Chunk includes several different TVs but both share two common TVs. I want to take the rendered (common) TV content of Page 1 and insert it into Page 2. I've been reading the docs but can't find a way to do it.

    Thanks
      Todd
    • I should think that you should be able to use @EVAL ... and use code to fetch the value for Page 1.

      @EVAL $page = $modx->getObject('modResource', 1);
      return $page->getTVValue('myTV');


      Is there really a need for this to be a TV? Could it not be a snippet that fetches the value for the TV in Page 1? @EVAL in a TV is not really the best way to get specified element content.

      [ed. note: sottwell last edited this post 11 years, 10 months ago.]
        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
        • 40088
        • 708 Posts
        Quote from: sottwell at Jul 20, 2012, 05:03 AM
        Is there really a need for this to be a TV? Could it not be a snippet that fetches the value for the TV in Page 1? @EVAL in a TV is not really the best way to get specified element content.

        I'm pretty new to MODX so it's very possible that a TV isn't the best option in this case. If it can be done with a Snippet instead then that's fine with me. I'm just not sure how to do that.

        Thanks
          Todd
        • These chunks are in the resource content? Chunk A in page 1, and Chunk B in page 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
            • 40088
            • 708 Posts
            Not sure what you mean by 'resource content'. I put the Chunk(s) tag in the Resource(s) template, if that's what you mean.
              Todd
            • So all pages using the template get both chunks? Can you post the affected part of the template's HTML code showing the chunk placement? (use the < > code button to show the code properly)
                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
                • 3749
                • 24,544 Posts
                Susan is referring to the "Resource Content" field of the Create/Edit Resource panel, though putting them in the template seems fine.

                Here's a generic snippet (untested) that will return the value of any TV for any Resource:

                [[!ShowTv? &tvId=`12` &resourceId=`14` &render=`0`]]
                

                <?php
                /* ShowTv snippet */
                
                $rid = $scriptProperties['resourceID'];
                $render = isset($scriptProperties['render']) && $scriptProperties['render'];
                $tv = $modx->getObject('modTemplateVar', $scriptProperties['tvId']);
                
                if ($tv) {
                    return $render? $tv->renderOutput($rid)  : $tv->getValue($rid);
                } else {
                   return "TV Not Found";
                }
                


                If &render is 0 or missing, you'll get the raw value of the TV, which will be faster if you don't need MODX to render it.


                BTW, if the value will be shared across multiple resources, you might consider making it a System Setting, which would be available anywhere as:

                [[++SettingName]]



                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 11 years, 10 months ago.]
                  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
                  • 40088
                  • 708 Posts
                  No. There are 2 templates.

                  Page 1 uses Template 1 and Chunk A
                  Page 2 uses Template 2 and Chunk B

                  Chunks A and B share two TVs ('projectName' and 'projectEmail').

                  From Template 1:

                  <!-- !Begin Project Info -->
                  				
                  [[$projectInfo]]
                  
                  <!-- !End Project Info -->


                  And Chunk A 'projectInfo' (above):

                  <ul>
                  <li>[[*projectName]]</li>
                  <li>[[*projectEmail]]</li>
                  </ul>


                  I want to insert the values for 'projectName' and 'projectEmail' from Page 1/Template 1 into Page 2/Template 2.

                  Hopefully that makes sense.
                    Todd
                  • Ok, different templates.

                    For the TV in #2, use a snippet like BobRay suggested instead of TV tags. If you don't want to edit the TV for resource #2, then don't have its template assigned to the TV.
                      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
                      • 40088
                      • 708 Posts
                      So if I used Bob's example above I would create 2 Snippets to replace each TV, 'projectName' and 'projectEmail'. Is that correct?
                        Todd