I'm working with CCK and Contemplate modules. Basically, I don't want any of the field data displaying if it's corresponding form has no values entered. Here's what I've tried so far:

<?php if ($field_author) : ?>
  <p class="item"><b>Author:</b>
    <?php foreach ((array)$field_author as $item) { ?>
      <?php print $item['view']  ?>
    <?php } ?>
  </p>
<?php endif;?>

Just to clarify, I don't want to <b>Author:</b> displayed if there's no data entered in the $field_author field.

Thanks!

Comments

phuc77’s picture

Perhaps try checking if your $field_author has any data with the count function.

if (count($field_author) > 0)
solidarity’s picture

Tried it, but the field is still showing up. Perhaps I inserted your code wrong? Take a look:

<?php if (count($field_author) > 0) : ?>
  <p class="item"><b>Author:</b>
    <?php foreach ((array)$field_author as $item) { ?>
      <?php print $item['view']  ?>
    <?php } ?>
  </p>
<?php endif;?>
phuc77’s picture

If $field_author is an object, perhaps you have to cast it to an array first like you do in the foreach statement before you run count.

ridefree’s picture

hmmm looking to figure out the same issue... must be a way :) will keep lookin