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!
$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;
?>
that works great - thanks.