Tuesday, May 21 2013
How to print fields on a views tpl
Drupal core fields:
<?php print $fields['title']->content; ?>
<?php print $fields['body']->content; ?>
<?php print $fields['nid']->content; ?>
Print the teaser:
<?php print $fields['teaser']->content; ?>
CCK fields:
<?php if ($fields['field_location_value']): ?>
<?php print $fields['field_image_fid']->content; ?>
If a field is optional, you might want to say "if field is not empty", like this:
<?php if (!empty($fields['field_image_fid']->content)) {
print $fields['field_image_fid']->content; }
?>
Especially if you want to add a div or h2 around the print, like this:
<?php if ($fields['field_location_value']): ?>
<div class="sample"><?php print $fields['field_location_value']->content; ?></div>
<?php endif; ?>
<?php if ($fields['field_venue_value']): ?>
<<div class="sample">><?php print $fields['field_venue_value']->content; ?></div>
<?php endif; ?>
Finally, here's a great tutorial on views row theming from the good folks at Mustardseed Media [source]