My issue is that I have embedded a view into my page but I need to check that it is empty. I am using this piece of code to do so. Can somebody tell me what I am doing wrong. It seems that if I put the view into a string that no matter what the varible will never be empty. I'm fairly new to php but I can tweak code.

    <?php $views_arg = views_embed_view("articles", "block_2", $fields["nid"]->content ); ?>
    <?php if ($views_arg == NULL || $views_arg == "") { ?>
		<div class="page"></div><ul><li><?php print $views_arg; ?></li></ul>
    <?php }; ?>

Comments

bpeter’s picture

The views_embed_view is the easiest way to embed views. It is not too flexible but easily can be broken away. You should do this way:

<?php
$view = views_get_view('articles');
if ($view) {
  $views_arg = $view->preview('block_2', array($fields['nid']->content));
  if (!empty($view->result)) { ?>
<div class="page"></div><ul><li><?php print $views_arg; ?></li></ul>
<?php
  }
}
?>
darrellhq’s picture

Thanks. Mine works but your code is really clean and efficient. Just what I was looking for.