We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28000 ☆ A M B ☆
    • 397 Posts
    I am using taglister to print out a list of tags on a page. The client wants however a custom way to show the results. He does not want to just show a results list that getResourcesTag spits out but the following:

    Each page that uses tags can be 1 of 3 possible templates. Each template has its own layout.

    Also each result listed by getResourcesTag will show full content of this page.

    I have templates with IDs of 4,5,6. Each one is assigned a layout.

    I then made corresponding Chunks that shows the layout.

    In my tpl for getResourcesTag, I am simply calling up my snippet and giving the snippet the ID of the resource

    [[!getTagList? &id=`[[+id]]` &debug=`1`]]

    The following code is my snippet getTagList:
    $output='';
    
    $criteria = $modx->newQuery('modResource');
    $criteria->where(array(
       'id' => $id,'published' => 1,
        'deleted' => 0 
    ));
    $resource = $modx->getObject('modResource',$criteria);
    
    $template=$resource->get('template');
      
    switch($template){
        
        case 4: $resourceArray=$resource->toArray();
        $resourceArray['textblock2']=$resource->getTVValue('textblock2');
        $resourceArray['image']=$resource->getTVValue('image.landscape');
        $resourceArray['tags']=$resource->getTVValue('tags');
        $resourceArray['image3']=$resource->getTVValue('image.portrait3');
        $resourceArray['image4']=$resource->getTVValue('image.portrait4');
        $output.=$modx->getChunk('landscapeTpl',$resourceArray);
        break;
        
        case 5: $resourceArray=$resource->toArray();
        $resourceArray['textblock2']=$resource->getTVValue('textblock2');
        $resourceArray['image1']=$resource->getTVValue('image.portrait1');
        $resourceArray['image2']=$resource->getTVValue('image.portrait2');
        $resourceArray['image3']=$resource->getTVValue('image.portrait3');
        $resourceArray['image4']=$resource->getTVValue('image.portrait4');
        $resourceArray['tags']=$resource->getTVValue('tags');
        $output.=$modx->getChunk('portraitTpl',$resourceArray);
        break;
        
        case 6: $resourceArray=$resource->toArray();
        $resourceArray['textblock2']=$resource->getTVValue('textblock2');
        $resourceArray['textblock3']=$resource->getTVValue('textblock3');
        $resourceArray['image1']=$resource->getTVValue('image.quad1');
        $resourceArray['image2']=$resource->getTVValue('image.quad2');
        $resourceArray['tags']=$resource->getTVValue('tags');
        $output.=$modx->getChunk('quadratTpl',$resourceArray);
        break;
        
        
        };
    
    if ($debug==1){
    $output.="<div>template:".$template." id:".$id."</div>";}
    
    return $output;


    My problem is that sometimes during the loop, it cannot parse out the chunk. If I have debug set to 1, I can then see which template and which ID. These are always correct. So it just breaks out of the switch case and shows that data.

    Can someone look at my code and see where and why it would sometimes not be able to parse out the code?

    The chunks that it calls are following:

    landscaptTpl
    <article class="portfolio_wrapper clearfix">
        <div class="portfolio_text">
            <h2>[[+longtitle]]</h2>
            [[+content]]
        </div>
        <aside class="tags">
             [[!toLinks? &items=`[[+tags]]` &target=`13`]]
        </aside>
        <figure class="landscape">
            <img src="[[+image:phpthumbof=`w=670&q=90`]]" alt="Landscape Bild" />
        </figure>
        
          [[+textblock2:notempty=`
         
         <div class="portrait_float clearfix">
            <div class="secondary_text">
                [[+textblock2]]
            </div>
         
         `]]
        
            [[+image3:notempty=`
            <figure class="portrait3">
                <img src="[[+image3:phpthumbof=`w=162&h=125&zc=1&q=90`]]" alt="Portrait 3" />
            </figure>
            `]]
            [[+image4:notempty=`
            <figure class="portrait4">
                <img src="[[+image4:phpthumbof=`w=162&h=125&zc=1&q=90`]]" alt="Portrait 4" />
            </figure>
            `]]
            
     [[+textblock2:notempty=`</div>`]]    
        
    </article>


    portraitTpl
    <article class="portfolio_wrapper clearfix">
        <div class="portfolio_text">
            <h1>[[+longtitle]]</h1>
            [[+content]]
        </div>
        <aside class="tags">
             [[!toLinks? &items=`[[+tags]]` &target=`13`]]
        </aside>
        <div class="portrait_images clearfix">
            <figure class="portrait1">
               <img src="[[+image1:phpthumbof=`w=330&h=470&zc=1&q=90`]]" alt="Portrait 1" />
            </figure>
            <figure class="portrait2">
               <img src="[[+image2:phpthumbof=`w=330&h=470&zc=1&q=90`]]" alt="Portrait 2" />
            </figure>
        </div>
        
         [[+textblock2:notempty=`
         
         <div class="portrait_float clearfix">
            <div class="secondary_text">
                [[+textblock2]]
            </div>
         
         `]]
        
            [[+image3:notempty=`
            <figure class="portrait3">
                <img src="[[+image3:phpthumbof=`w=162&h=125&zc=1&q=90`]]" alt="Portrait 3" />
            </figure>
            `]]
            [[+image4:notempty=`
            <figure class="portrait4">
                <img src="[[+image4:phpthumbof=`w=162&h=125&zc=1&q=90`]]" alt="Portrait 4" />
            </figure>
            `]]
            
     [[+textblock2:notempty=`</div>`]]    
            
        
    </article>


    and quadratTpl

    <article class="portfolio_wrapper clearfix">
        <div class="portfolio_text">
            <h2>[[+longtitle]]</h2>
            [[+content]]
        </div>
        <aside class="tags">
             [[!toLinks? &items=`[[+tags]]` &target=`13`]]
        </aside>
        <figure class="quad1">
        <img src="[[+image1:phpthumbof=`w=333&h=333&q=90&zc=1`]]" alt="Quad 1" class="quad_image" />
           <figcaption class="caption_quad1">
                [[+textblock2]]
           </figcaption>
        </figure>
       
        <figure class="quad2">
         <img src="[[+image2:phpthumbof=`w=333&h=333&q=90&zc=1`]]" alt="Quad 1" class="quad_image" />
            <figcaption class="caption_quad2">
                [[+textblock3]]
           </figcaption>
        </figure>
          
    </article>
      Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
      • 3749
      • 24,544 Posts
      It might help to have some sanity checks.


      $resource = $modx->getObject('modResource',$criteria);
      
      if (! $resource) {
          $output .= '<p>RESOURCE NOT FOUND</p>';
      }



      Then, at the bottom of your switch statement:


      default:
         $output .= '<p>Unknown Template: ' . $template . '</p>';
         break;


        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
        • 28000 ☆ A M B ☆
        • 397 Posts
        Thanks Bob,

        I definitely need some sanity!

        I added your recommendation and I still get the same result. The error only happens like 1 in 10 page refreshes. When the error happens, it still prints out just my debug line. It doesn't even print the default case that you gave to me!

        Here is now the code:
        $output='';
        
        $criteria = $modx->newQuery('modResource');
        $criteria->where(array(
           'id' => $id,'published' => 1,
            'deleted' => 0 
        ));
        $resource = $modx->getObject('modResource',$criteria);
        if (!$resource) {
            $output .= '<p>RESOURCE NOT FOUND</p>';
        }
        $template=$resource->get('template');
          
        switch($template){
            
            case 4: $resourceArray=$resource->toArray();
            $resourceArray['textblock2']=$resource->getTVValue('textblock2');
            $resourceArray['image']=$resource->getTVValue('image.landscape');
            $resourceArray['tags']=$resource->getTVValue('tags');
            $resourceArray['image3']=$resource->getTVValue('image.portrait3');
            $resourceArray['image4']=$resource->getTVValue('image.portrait4');
            $output.=$modx->getChunk('landscapeTpl',$resourceArray);
            break;
            
            case 5: $resourceArray=$resource->toArray();
            $resourceArray['textblock2']=$resource->getTVValue('textblock2');
            $resourceArray['image1']=$resource->getTVValue('image.portrait1');
            $resourceArray['image2']=$resource->getTVValue('image.portrait2');
            $resourceArray['image3']=$resource->getTVValue('image.portrait3');
            $resourceArray['image4']=$resource->getTVValue('image.portrait4');
            $resourceArray['tags']=$resource->getTVValue('tags');
            $output.=$modx->getChunk('portraitTpl',$resourceArray);
            break;
            
            case 6: $resourceArray=$resource->toArray();
            $resourceArray['textblock2']=$resource->getTVValue('textblock2');
            $resourceArray['textblock3']=$resource->getTVValue('textblock3');
            $resourceArray['image1']=$resource->getTVValue('image.quad1');
            $resourceArray['image2']=$resource->getTVValue('image.quad2');
            $resourceArray['tags']=$resource->getTVValue('tags');
            $output.=$modx->getChunk('quadratTpl',$resourceArray);
            break;
            default:
           $output .= '<p>Unknown Template: ' . $template . '</p>';
           break;
            
            };
        
        if ($debug==1){
        $output.="<div>template:".$template." id:".$id."</div>";}
        
        return $output;


        I also get the following error in the error log, but not sure what it means:

        [2013-03-01 02:21:26] (ERROR @ /index.php) sources.modMediaSource::getSelectColumns() is not a valid static method.
        [2013-03-01 02:21:26] (ERROR @ /index.php) Error 42S22 executing query: SELECT `modChunk`.`id` AS `modChunk_id`, `modChunk`.`source` AS `modChunk_source`, `modChunk`.`property_preprocess` AS `modChunk_property_preprocess`, `modChunk`.`name` AS `modChunk_name`, `modChunk`.`description` AS `modChunk_description`, `modChunk`.`editor_type` AS `modChunk_editor_type`, `modChunk`.`category` AS `modChunk_category`, `modChunk`.`cache_type` AS `modChunk_cache_type`, `modChunk`.`snippet` AS `modChunk_snippet`, `modChunk`.`locked` AS `modChunk_locked`, `modChunk`.`properties` AS `modChunk_properties`, `modChunk`.`static` AS `modChunk_static`, `modChunk`.`static_file` AS `modChunk_static_file`, `` FROM `modx_site_htmlsnippets` AS `modChunk` LEFT JOIN `modx_media_sources` `Source` ON `modChunk`.`source` = `Source`.`id` WHERE `modChunk`.`name` = ? ORDER BY `modChunk`.`id` ASC  - Array
        (
            [0] => 42S22
            [1] => 1054
            [2] => Unknown column '' in 'field list'
        )
          Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
          • 28000 ☆ A M B ☆
          • 397 Posts
          Could it be that when the TV is empty that it triggers this? But wouldn't it just be consistent and always not show the chunk then?
            Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
            • 3749
            • 24,544 Posts
            There may be a problem somewhere else in your code. It looks like you're trying to get chunk fields from a mediaSource object.

            Or maybe one of your chunks is static and has an invalid media source defined.
              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
              • 28000 ☆ A M B ☆
              • 397 Posts
              Right as of now it seems to be a caching issue. In my template I am referring to a chunk and within this chunk is the getResourceTag call which is then calling a chunk that is calling a snippet that is then calling a chunk and displaying the final information. After I uncached the first chunk call within the template, the error seems to have vanished. So I hope that was it wink
                Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                • 3749
                • 24,544 Posts
                When you start nesting things that deeply, it gets really difficult (sometimes impossible) to get the caching right. It also tends to slow down page loads. If I need something that complex, I usually try to write my own custom snippet to do the whole job.
                  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