We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27672
    • 168 Posts
    i’m writing a snippet, which i would like to have output an error if a the specified tpl chunk does not exist.

    is there a built in method like $modx->verifyChunkExists(’chunkName’); or something like that? or do i a need to query the modx_site_htmlsnippets table? would obviously rather use an existing method, but couldn’t seem to find one. thanks!
      • 4041
      • 788 Posts
      $modx->getChunk("chunkname") will return an empty string if the chunk doesn’t exist.

      <?php
      $output ='';
      
      $mychunk = isset($tpl_chunk) ? $modx->getChunk($tpl_chunk) : '';
      
      if($mychunk ==''){
         // the chunk was empty
         $output .='<p>error message here</p>';
      }else{
         $output .=$mychunk;
      }
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 27672
        • 168 Posts
        that works great - thanks.