I want to customize the output of a field on my site so I made a custom views template. Here's the code:

<?php foreach ($row->field_field_location_taxonomize_terms as $data): ?>

  <?php if ($data['rendered']['#markup'] == 'Unknown'): ?>
  <?php elseif ($data['rendered']['#markup'] == 'United States of America (USA)'): ?>
    <?php print 'USA'; ?> 
  <?php elseif ($data['rendered']['#markup'] == 'United Kingdom (UK)'): ?>
    <?php print 'UK'; ?> 
  <?php else: ?>
    <?php print $data['rendered']['#markup']; ?> 
  <?php endif; ?>

<?php endforeach; ?>

As far as editing the output, this works fine. However, if the field is empty, the Label (set in views) for the field will still be printed, even though I have Hide if empty checked under No Results Behavior. If I remove my custom template, then the label is hidden when there is no value, so there must be something wrong with my template. Any ideas?

1 Answer 1


Quick and dirty, how about turning the label for this field off in Views and add something like:

<?php if (!empty($row->field_field_location_taxonomize_terms)): ?>
<?php endif; ?>

at the top of this template? (Changing up the HTML around Label: to match your system and t()'ing it, etc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.