We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    I don't understand php either, but you are among experts. I can read it a bit and know what is happening, on good days at least. wink

    I think its like this, but I could be off. You're gonna have two chunks, no extra snippet as you have grabbed all the 'data' or 'items' in the snippet you do have. That's the php and we are just worried about the output.

    If the data you are looking for is anywhere in that array of data, you've got it in memory and can output it.

    Also watch out, I believe the placeholder for these values is one bracket, [+item], rather than two. Two brackets is Modx shorthand code, for chunks and snippets and other stuff too. [[$ChunkCall]] and [[!UncachedSnippetCall]]

    Start with container and drill down

    <div class="container">
    
    [[$OuterChunkTpl]]
    
    </div>


    OuterChunktpl contains

    <p>[+total_count] and [+weight]</p>
     <ul>
     [[$InnerChunkTpl]]
     </ul>


    and InnerChunkTpl contains something like

    <li>[+defect rate]</li>
          <li>[+]</li>


    Now I beleive you can output all the data if you wish, when the snippet is grabbing just what you need and not necessarily everything in the json. That's an area I don't understand well but it looks a bit like this

    <li>[+value]</li>


    and then all the values in the array will be listed.

    Also, the first example of the page under Processing Chunk via the API might be useful for you, its a simple snippet and chunk for output, to get the list of resources

    https://docs.modx.com/revolution/2.x/making-sites-with-modx/structuring-your-site/chunks
    • discuss.answer
      • 3749
      • 24,544 Posts
      I would do it this way, since (if I'm understanding your use case) you need to use the inner chunk multiple times and you should only need one snippet:

      Outer Tpl

      <p>[[+total_count]] and [[+weight]]</p>
       <ul>
       [[+inner]]
       </ul>


      Then in the snippet (pseudocode):

      $output = '';
      $outerFields = array(
         // outer chunk placeholders
      );
      
      $output .= $modx->getChunk('outerTpl', $OuterFields);
      
      $innerOutput = '';
      
      foreach ($item as $item) {
         $innerFields = array(
           // inner chunk placeholders for this item
         );
         $innerOutput .= $modx->getChunk('innerTpl', $innerFields);
      }
      
      /* Insert the inner stuff into the middle of the $output by replacing
         the inner tag with the inner output */
      
      $output = str_replace('[[+inner]]', $innerOutput, $output);
      return ($output);


      In the last line, str_replace() will be much faster than making MODX parse that placeholder tag.

      [ed. note: BobRay last edited this post 5 years, 7 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
        • 54063
        • 14 Posts
        Got it working, thank you!

        FYI the single case square brackets didn't work it did need to be the [[+placeholder]] syntax.

        Thanks again
          • 3749
          • 24,544 Posts
          Sorry, I copied Nuan88's typo without noticing.
            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
            • 46886
            • 1,154 Posts
            Sorry I messed up, I'll take the blame. Its double brackets all around, I didn't realize it.

            Sparker thanks for pointing it out for me. We started out with [+weight] and I thought that worked
              • 3749
              • 24,544 Posts
              We can share the blame. wink

              I should have noticed it.
                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