We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17412
    • 270 Posts
    Hi,
    I’m using the Create TV-Based Chunks snippets to output a list of chunks into any given template that can then be turned on/off with a checkboxes.
    Ref: http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

    I have an issue with using the Ditto snippet inside a chunk.
    As I understand it - snippets can run inside chunks though right now - the snippet text is printed into the page rather than running and outputting required html.

    So I’m sure TV Based Chunks is filtering and preventing snippets from running in chunks - any ideas on how to modify the code to permit snippets?

    Thanks!

    Al


    Here’s the code for the TV-Based Chunks:

    Get Chunks Snippet
          <?php
          $q_chunks = $modx->db->query('
          SELECT
          chunk.*
          FROM '.$modx->getFullTableName('site_htmlsnippets').' AS chunk
          INNER JOIN '.$modx->getFullTableName('categories').' AS category
          ON chunk.category = category.id
          WHERE
          category.category IN ("'.$category.'")
          ORDER BY
          name
          ');
          $ar_chunks = array();
          while ($row = $modx->db->getRow($q_chunks)) {
          $ar_chunks[] = $row['name'];
          }
          $l_chunks = implode("||",$ar_chunks);
          return $l_chunks;
    ?>
    
    


    Chunk List Parser
     
          <?php
          $ar_chunks = split(',',$chunks);
          $ar_chunks = array_unique($ar_chunks);
          $output = '';
          foreach ($ar_chunks as $chunk) {
          if ($chunk != '') {
          $c = $modx->getChunk($chunk);
          if ($c) $output .= $c;
          }
          }
          if ($output != '' && isset($wrapperdiv)) {
          $output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
          }
          return $output;
          ?>
    


      • 4172
      • 5,888 Posts
      Did you try changing the Ditto-call from uncached [!Ditto.........!] to cached [[Ditto..........]] snippet-call?
      When you parse chunks from in a snippet you have to revers cached/unchached snippet-calls in these chunks.
      Thats what I have found in most of this situations.

      you can also try

      $c='{{'.$chunk.'}}';


      or

      $c=$modx->parseDocumentSource( '{{'.$chunk.'}}');

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17412
        • 270 Posts
        Thanks for your help Bruno.
        I have tried calling Ditto cached and uncached.
        Cached give this error:

        « MODx Parse Error »
        MODx encountered the following error while attempting to parse the requested resource:
        « PHP Parse Error »
         
        PHP error debug
          Error: 	Invalid argument supplied for foreach()	 
          Error type/ Nr.: 	Warning - 2	 
          File: 	/var/www/vhosts/theclubandspachester.co.uk/httpdocs/assets/snippets/ditto/classes/template.class.inc.php	 
          Line: 	50	 
          Line 50 source: 	foreach ($templates as $tplName=>$tpl) { 	 
         
        Parser timing
          MySQL: 	0.0018 s	(10 Requests)
          PHP: 	0.0640 s	 
          Total: 	0.0658 s


        Uncached just prints the snippet text into the page.

        I tried editing Chunk List Parser snippet as you recommended (tried both ways) though it still prints the snippet text as before.

        Thanks,

        Al
          • 4172
          • 5,888 Posts
          seems the array-count of $templates is cero at this point.

          can you show us your chunkcontent where you have your ditto-call

          or perhaps try to find out what is the content of $templates at this point.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 17412
            • 270 Posts
            Quote from: Bruno17 at Jun 13, 2009, 10:41 AM

            seems the array-count of $templates is cero at this point.

            can you show us your chunkcontent where you have your ditto-call

            Hi Bruno,

            Here’s the chunk content: "Latest news"

            [!Ditto?startID=`2` &tpl=`latest-news-side` &extenders=`summary` &display=`2` &sortBy=`pub_date` &sortDir=`desc` &dateSource=`pub_date` &dateFormat=`%d %b %y` &paginate=`0`!]
            


            latest-news-side tpl

            <div class="list-item-row">
            <div class="list-item-image">[+list-image+]</div><!-- / list-item-image -->
            <div class="list-item-detail">
            <h3><a href="[~[+id+]~]" title="[+title+]">[+title+]</a></h3>
            [+summary+] <a href="[~[+id+]~]" title="Read more about [+title+]">Read more »</a>
            </div><!-- / list-item-detail -->
            </div><!-- / list-item-row -->
            


            Thanks.

              • 17412
              • 270 Posts
              Evening all,

              This issue has been resolved - please find the amended snippet code for parse_chunks snippet below.
              The snippet now allows snippets embedded in chunks to run correctly.

              Full credits and gratitude to Aleksander (Modx user: Alik)

              <?php
              $ar_chunks = split(',',$chunks);
              $ar_chunks = array_unique($ar_chunks);
               
              $output = '';
               
              foreach ($ar_chunks as $chunk) {
                if ($chunk != '') {
                  $c = $modx->getChunk($chunk); /*** now string $c contains chunk's content -> raw mix of html and modx tags ***/
                  /*** now it is a time to parse snippet tags in string $c ***/
                  $c = $modx->evalSnippets($c); /*** yeah! done! ***/
                  /*** of course, it might be done with a single step :)
                    $output .= $modx->evalSnippets($modx->getChunk($chunk));
                    important notice: evalSnippet function recognizes only cached version of snippets [[...]]
                   ***/
                  if ($c) $output .= $c;
                }
              }
               
              return $output;
              ?>
                • 10567
                • 6 Posts
                I love this code, but can’t figure out a way to set the order of the included chunks. Any ideas/suggestions? The current ordering is simply by chunk name. I would like to be able to control this per page via TVs, or...???
                  • 4172
                  • 5,888 Posts
                  doesn’t it work this way?:

                  make the TV not a checkbox, but Text-TV and write your chunks you want comma-seperated.

                  chunkA,chunkB,chunkC,chunkD

                  chunkB,chunkA,chunkF,chunkC
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 17412
                    • 270 Posts
                    Quote from: gcole at Jul 08, 2009, 11:22 PM

                    I love this code, but can’t figure out a way to set the order of the included chunks. Any ideas/suggestions? The current ordering is simply by chunk name. I would like to be able to control this per page via TVs, or...???

                    You’re right. It’d be nice to control the order per page. Currently I just use a naming convention:

                    a-chunk-name
                    b-chunk-name
                    c-chunk-name

                    Bruno’s solution will give you more flexibility though perhaps more margin for error.

                    Just wondering whether a ManagerManager widget could be used?

                    Add widgets to Manager fields - e.g. Del.icio.us-like tag interface, color picker, image preview
                    With a bit of jquery and show the chunks as tags that are clicked to add them to the text box?
                      • 10567
                      • 6 Posts
                      Thanks guys! I’ll give both a try. This is my first MODx site and I am blown away with how flexible it is (for the most part). Looks like ManagerManager has some really nice features. Bruno - I like the solution, but do worry a bit about typos. The site will be maintained by staff members that aren’t super technical, so having a straight-forward/simple UI would be preferred. The text entry would do the trick if I can make the chunk names easy to use too.