We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    I have a fairly complex page which renders several divs. Each div contains a header, repeating detail information and a footer.

    I use a snippet to collect all relevant information from the database. Then in a loop, the snippet produces the required output by parsing several chunks:

    for ($i=0; $i<$divCounter; $i++) [
      $output = $mdodx->parsechunk('headerChunk', ....);
      for ($j=0; $j<$detailInDivCounter; $j++) {
        $output = $output . $mdodx->parsechunk('detailChunk', ....);
      }
      $output = $output . $mdodx->parsechunk('footerChunk', ....);
    }
    


    The above works, but there’s a lot of parsing going on and I was wondering whether there’s a smarter approach...
      MODx Revolution / MAMP / OS X
      • 3749
      • 24,544 Posts
      One faster method might be to store all the chunks as an array inside the snippet (or in an include file) and use str_replace() to do the parsing yourself. It would make editing the chunks less convenient, and if the page load time is acceptable, it might not be worth the trouble. .
        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