On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • 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
      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 11 months, 4 weeks 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
      • Got it working, thank you!

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

        Thanks again
        • 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
          • 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
            • 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