How to print a view in node.tpl.php only if it's not empty Views can be printed in tpl.php files with this code:

&lt;?php print views_embed_view('myview','block_1'); ?&gt;


However, if that view is empty, the view block code will be printed anyway:

&lt;div class="view view-myview view-id-myview view-display-id-block_1 view-dom-id-abc123..."&gt;&lt;/div&gt;


Is it possible to check if the view has any results first and then print it if it does? E. g.:

&lt;?php if ($view_myview,block_1): ?&gt;
&lt;?php print views_embed_view('myview','block_1'); ?&gt;
&lt;?php endif; ?&gt;
You can check it using the below code

&lt;?php 
$viewName = 'myview';
$displayid = 'block_1'; 

$view = views_get_view($viewName,$displayid);
$view-&gt;execute();
$reviewCount = count($view-&gt;result); //It will return number of results
if($reviewCount&gt;0){
print views_embed_view($viewName,$displayid); 
}
?&gt;


Hope it will help.