Customizing views output- rewrite output to show an image based on key value I want to use a views template to customize the output of the gender field on my user profile.  The gender field is a select list, and the key values are as follows:


f (female)
m (male)
o (other)


I created a template file, views-view-field--field-acc-gender.tpl.php.  I have the images saved in my theme's directory.  I can write an if statement to check against the key value, but how do I get the value of the field?  (This is probably a straightforward question, but I just learned about views templates today.)

I tried the following in views-view-field--field-acc-gender.tpl.php:

&lt;?php 
if ($output == 'M') {
  print 'male';
}
else if ($output == 'F') {
  print 'female';
}
else {
  print 'other';
}


However, my view still simply prints out M or F instead of male or female.
You should be able to access the data from $row array from inside the template file. So:

$data = $row-&gt;field_field_acc_gender;

// This may not necessarily be the correct structure of your field's data.
// So you may want to do print_r($data) or dpm($data) to see correct structure.
$gender = $data[0]['raw']['value']; 

switch($gender) {
  case 'M':
    print('Male');
    break;
  case 'F':
    print('Female');
    break;
}