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

    I'm using Revolution 2.2rc3, and I'm also reading/studing MODX: The Official Guide, Chap 6, pg 246, where I'm trying to re-create "A Simple Example" of a TV-Based Chunk.

    Here's the book's code:
    <?php    
        /* Code for the getChunks Snippet */
    
    	/* Get the category object */
    	$category = $modx->getObject('modCategory',array('category'=>$category));
    
    	/* Get the chunk objects in the category */
    	$chunkArray = $category->getMany('Chunks');
    
    	$chunkNames=array();
    
    	/* Put the chunk names in an array */
    	foreach($chunkiArray as $chunk) {
    	$chunkNames[] = $chunk->get('name');
    	}
    
    	/* Format the chunk names for the TV and return them */
    	$output = implode("||",$chunkNames);
    	return $output;
        ?>


    Here's the code I've inputed into my [[getChunks]] snippet:
    /* Code for the getChunks Snippet */
    
    /* Get the category object */
    $category = $modx->getObject('modCategory',array('category'=>$category));
    
    /* Get the chunk objects in the category */
    $chunkArray = $category->getMany('Chunks');
    
    $chunkNames=array();
    
    /* Put the chunk names in an array */
    foreach($chunkiArray as $chunk) {
    	$chunkNames[] = $chunk->get('name');
    }
    
    /* Format the chunk names for the TV and return them */
    $output = implode("||",$chunkNames);
    return $output;


    When I view the TV [[*Warranty]] in my resource edit tab, there is only 1 radio button visible, and selecting this button has no results on the front end of the site.

    1. I created a new resource with template that has access to the TV
    2. I created 3 chunks and assigned them to the Warranty category
    3. in input options value of TV I placed:
    @EVAL return $modx->runSnippet('getChunks',array('category'=>'Warranty'));


    Something's not working properly and I could use some feedback please. If there's some important information I've left out, please advise, and accept my apologies for not being clearer from the start. [ed. note: ironchip last edited this post 14 years, 8 months ago.]
      • 3749
      • 24,544 Posts
      Double check the spelling of 'Warranty' in the @EVAL and the actual name of the category.

      If that doesn't work, try changing the first line of code in the snippet to this:


      $category = $modx->getObject('modCategory',array('category'=>$scriptProperties['category']));



      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 4041
        • 788 Posts
        One thing I notice is a misspelling here:
        foreach($chunkiArray as $chunk) {


        shouldn't that be:
        foreach($chunkArray as $chunk) {
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 35082
          • 57 Posts
          You guys are awesome. I've checked and rechecked that code over and over at least 20 dif times I know. But it took me posting to forum to find the mis-pelled word. How embarrassing.

          Changed
          foreach($chunkiArray


          to
          foreach($chunkArray


          Now everything works as it should.