Hi all,

I've made a customized node template that I've named node-events.tpl.php. In that, I'm customizing the layout, having fields appear with code in the following fashion:

<?php print $node->field_eventvenue[0]['view']; ?>

My problem is this, I'm using graphics in conjunction with each field, but I only want them to appear, both the graphic and the field, ONLY if there is data. If no data, then I don't want it to show at all. For instance, let's say it normally looks like so when all three fields have data:

[graphic 1]: Field 1 Text
[graphic 2]: Field 2 Text
[graphic 3]: Field 3 Text

Right now, if Field 2 doesn't have data I'm seeing:

[graphic 1]: Field 1 Text
[graphic 2]:
[graphic 3]: Field 3 Text

The 2nd graphic still appears, but the text is blank. What I'd rather see is simply

[graphic 1]: Field 1 Text
[graphic 3]: Field 3 Text

Any advice on some php code I can wrap around the graphic and field that will check for data and determine if it appears or not?

Thanks for any help!

Comments

vertazzar’s picture

you do it like this :

<?php if (!empty($node->field_nameofthefield[0]['view'])): ?>
<div class="field field-type-text field-field-nameofthefield">
  <h3 class="field-label">Text</h3>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_nameofthefield[0]['view'] ?></div>
  </div>
</div></div>
    <?php endif; ?>

garzast’s picture

Thanks a million, vertazzar!