Theresa Arzadon-Labajo

Theming grouped multiple values in Views

Posted by Theresa Arzadon-Labajo (tarzadon) on Dec 15 2010
Tech Stuff >> Drupal
I have a View with a field called Content: Author and checked off "".  The multiple values print on multiple lines in divs:
A
B
C
but I wanted them to print out on a single line separated by commas:
A,B,C

However, when looking at the $row array in the theme templates, those field_author_value fields don't show up at all.  This post talks about it: http://drupal.org/node/763620

The way to theme it is to create a function called mytheme_content_view_multiple_field($items, $field, $values) in template.php and it is described here and here.

I followed this example:

I like it. One modification would be to call out the field you want to alter, so all other fields get rendered the stock way.

<?php
function mytheme_content_view_multiple_field($items, $field, $values) {
 
//drupal_set_message($field['field_name']);
 
if ($field['field_name'] == 'field_myfield' ) {
   
$output = '';
   
// Separate item values with my favorite separator.
   
$separator = ', ';
   
$array = array();
    foreach (
$items as $item) {
      if (!empty(
$item) || $item == '0') {
       
$array[] = $item;
      }
    }
    return
'<span class="field-item">'. implode($separator, $array) .'</span>';
  }
  else {
   
//else use the default function loacated at the bottom of cck/includes/views/content.views.inc
   
return theme_content_view_multiple_field($items, $field, $values);
  }
}


?>

Last changed: Feb 27 2020 at 4:12 PM

Back