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

    Hoping I can get some help troubleshooting. I have a few too many templates and I would like to tidy up by using TV based chunks for different template layouts, and for system templates.
    I have followed this excellent tutorial, and I am about 90% of the way there.
    http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

    My problem is that the dropdown list isn’t appearing in my template. The template picks up the default chunk that I have specified in the TV, but won’t show the list of other chunks to select.

    I’m not sure if I should be looking for the issue in the snippet getChunks, or in the @eval call (both below).

    @EVAL return $modx->runSnippet(‘getChunks’,array(‘category’=>’contentLayouts’));

    <?php
    /* Get the chunk objects */
    $c = $modx->newQuery(’modChunk’);
    $c->leftJoin(’modCategory’,’Category’);
    $c->where(array(
    ’Category.category’ => $category,
    ));

    $chunkArray = $modx->getCollection(’modChunk’,$c);

    $chunkNames=array();

    /* Put the chunk names into the array */

    foreach($chunkArray as $chunk) {

    $chunkNames[] = $chunk->get(’name’);

    }

    /* Format the chunknames as a delimited string for the TV */
    $l_chunks = implode("||",$chunkNames);
    return $l_chunks;
      • 3749
      • 24,544 Posts
      If you know the ID of the category, I think you could send that rather than the name and use something like this to get all the chunks in the category without a join:

      <?php
      /* get the chunk objects */
      
      $modx->getCollection('modChunk', array('category'=>$categoryId));


      You could also do this using the category name, but it would be a little slower:

      <?php
      $categoryObj = $modx->getObject('modCategory', array('category'=>$categoryName));
      $categoryId = $categoryObj->get('id'); 
      $modx->getCollection('modChunk', array('category'=>$categoryId));


        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