views-view-field.tpl.php - How to print multiple values? I've created a views template (based on views-view-field.tpl.php) because I want to exclude a certain value ('o') from being displayed.  I came up with the following code:

$data = $row-&gt;field_my_field;
$raw_value = $data[0]['raw']['value'];
$rendered_value = $data[0]['rendered']['#markup'];

if ($raw_value == 'o') {
}
else {
  print $rendered_value;
}


This works fine for a single value, but this field allows for multiple values (up to about 20).  How can I modify the code to print all of the values except, if present, 'o'?
You can do it in the template itself quite simply, something like:

&lt;?php foreach ($row-&gt;field_my_field as $data): ?&gt;

  &lt;?php if ($data['raw']['value'] == 'o'): ?&gt;
    // Output nothing, or placeholder, whatever
  &lt;?php else: ?&gt;
    &lt;?php print $data['rendered']['#markup']; ?&gt;
  &lt;?php endif; ?&gt;

&lt;?php endforeach; ?&gt;


This is a custom template for that particular field, and so should only be used with it (which can be done via preprocess). You might also need to be careful about the name of the field changing if the field's changed in the View.

The nicest approach I can think of is probably using hook_field_attach_view_alter():

function MYMODULE_field_attach_view_alter(&amp;$output, $context) {

  $field_name = 'field_test';
  $to_hide = array('o');

  if (isset($output[$field_name]['#field_name'])) {
    if ($field_name == $output[$field_name]['#field_name']) {
      foreach ($output[$field_name]['#items'] as $delta =&gt; $item) {
        if (in_array($item['value'], $to_hide)) {
          unset($output[$field_name][$delta]);
        }
      }
    }
  }
}


That will work for Views and a normal entity view. AFAIK you can use $context to detect whether you're in a View or not, but I can't remember what you'd check for exactly. (And if you later find you do want to display the field like this outside of Views, it's painless to change.)

HTH