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

    I'm stuck with this problem.

    I have created 2 TV's , one which has text input and another with image input.

    So i put that two TV's in a chunk:

    <div>
    <img src="[[*imageTV]]" alt />
    <p>[[*textTV]]</p>
    </div>


    and later that chunk in a template:

    ...code...
    <div class="center">
    [[$mainChunk]]
    </div>
    ...code...
    


    And when I create a new document with that template, it works fine. So I created 2 documents this way.

    Now, what I need is to fetch all the data of those pages and when I create a new document, to somehow "forward" that new info to another document where I need to show all those info.

    In that document I need something like this:

    <a href="firstDocumentURL">
    <div>
    <img src="firstImage"/>
    <p>firstText</p>
    </div>
    </a>
    <a href="secondDocumentURL">
    <div>
    <img src="secondImage"/>
    <p>secondText</p>
    </div>
    </a>
    <a href="aNewAddedDocumentURL1">
    <div>
    <img src="aNewAddedDocumentImage1"/>
    <p>aNewAddedDocumentText1</p>
    </div>
    </a>
    ...
    and so on
    


    So, I need to fetch all the URLs,images and text and to show them to another page.

    Is this somehow possible ? I am really stuck.

    Thank you. [ed. note: vucko2405 last edited this post 13 years, 6 months ago.]
      • 22840
      • 1,572 Posts
      Are these documents all under 1 parent ?

      You can use getResources to aggregate the data:

      [[!getResources? &parents=`22` &tpl=`mytemplate`]]


      Update the parent and tpl name.

      Create a chunk something like this:

      <div>
      <a href="[[+id]]"><img src="[[+imageTV]]"/></a>
      <p><a href="[[+id]]">[[*textTV]]</a></p>
      </div>
      


      http://rtfm.modx.com/display/ADDON/getResources
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Quote from: paulp at Mar 18, 2013, 09:42 AM
        Are these documents all under 1 parent ?

        You can use getResources to aggregate the data:

        [[!getResources? &parents=`22` &tpl=`mytemplate`]]


        Update the parent and tpl name.

        Create a chunk something like this:

        <div>
        <a href="[[+id]]"><img src="[[+imageTV]]"></a>
        <p><a href="[[+id]]">[[*textTV]]</a></p>
        </div>
        


        http://rtfm.modx.com/display/ADDON/getResources

        No reason to call getResources uncached there:

        [[getResources? &parents=`22` &tpl=`mytemplate`]]


        Your tpl is also off a bit:

        <div>
        <a href="[[+id]]"><img src="[[+tv.imageTV]]"></a>
        <p><a href="[[+id]]">[[+tv.textTV]]</a></p>
        </div>


        That said, yep, getResources sounds like the way to go tongue
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 42970
          • 27 Posts
          Thank you for the reply, will try it first thing in the morning.

          As I can see, I need to manual add for each page its ID. Is there a way to loop through those pages to get all the IDs ?
            • 36996
            • 211 Posts
            The example above assumes all your resources are under one parent (22), if that's the case you don't need to specify the resources, just the parent.
              • 42970
              • 27 Posts
              And what do you mean be parent(ID) ?

              All of those sites have the same tamplate. Is the template here the parent ?

              So in this situation would be:

              template_ID=7
              template_name=all_groups_template

              [[!getResources? &parents=`7` &tpl=`all_groups_template`]]
              ?
                • 22840
                • 1,572 Posts
                Nothing to do with the template it's the parent in the file tree, for example:

                About us (2)
                ----Meet the team (3)
                ----Contact Us (4)
                ----Our Location (5)

                In the above the parent would be 2 and get resources would take the content from everything under About Us
                  • 42970
                  • 27 Posts
                  I tried both of your answers but with no luck. What I did:

                  Created a file tree:

                  Sports(7)
                  ----Football(10)
                  ----Basketball(11)
                  ----Handball(12)

                  And all of those three documents (football,basketball,handball) have the same TV (imageTV) which I used to add one image to every document.

                  Created two chunks:

                  1. chunk -> "boxes"
                  <div>
                  <a href="index.php?id=[[+id]]"><img src="[[+imageTV]]"></a> <!-- I tried also [[+tv.imageTV]] -->
                  </div>
                  


                  2. chunk -> "all_boxes"
                  [[!getResources? &parents=`7` &tpl=`boxes`]] <!-- I tried also [[getResources? &parents=`7` &tpl=`boxes`]] -->
                  


                  And created a template:

                  3. template "box_tpl"
                  <!DOCTYPE html>
                  <html>
                  <head></head>
                  <body>
                  <div>
                  [[$all_boxes]]
                  </div>
                  </body>
                  </html>
                  


                  And add that template to document "sport_list".

                  And this is the result:

                  
                  <!DOCTYPE html>
                  <html>
                  <head></head>
                  <body>
                  <div>
                  <div>
                  <a href="index.php?id=14"><img src=""></a>
                  </div>
                  <div>
                  <a href="index.php?id=13"><img src=""></a>
                  </div>
                  <div>
                  <a href="index.php?id=5"><img src=""></a>
                  </div>
                  </div>
                  </body>
                  </html>
                  


                  What am I doing wrong ? I can fetch all of the IDs , but no image paths.

                  Thank you
                    • 42970
                    • 27 Posts
                    I solved is using :

                    1. chunk "boxes"

                    <div>
                    <a href="index.php?id=[[+id]]"><img src="[[+tv.imageTV]]" /></a>
                    </div>
                    


                    2. chunk "all_boxes"
                    [[getResources? &parents=`7` &tpl=`boxes` &includeTVs=`1`]]
                    


                    The &includeTVs=`1` tells we include all the TVs from the chunk.

                    Is this a valid approach? [ed. note: vucko2405 last edited this post 13 years, 7 months ago.]