When creating a view you are presented with two types of row styling: fields and node. If you choose node, you have the ability to choose to show the teaser of the node. In certain situations, you might want to choose fields row styling, but also show the teaser version of a field. This can be accomplished by creating a template file for your field and modify its contents with a bit of PHP code.
By clicking on the "Theme: Information" section on the view edit screen, you can see different options you have for overriding a view. In this case, I looked for the theme file that matched the field, name of the view, and the view type:
views-view-field--MYVIEWNAME--block--MYFIELD.tpl.phpClicking on the link to the left of the theme file name options will show you the default contents of that file. Example: "Field Node: Body (ID: body)"
<?php
// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
/**
* This template is used to print a single field in a view. It is not
* actually used in default Views, as this is registered as a theme
* function which has better performance. For single overrides, the
* template is perfectly okay.
*
* Variables available:
* - $view: The view object
* - $field: The field handler object that can process the input
* - $row: The raw SQL result that can be used
* - $output: The processed output that will normally be used.
*
* When fetching output from the $row, this construct should be used:
* $data = $row->{$field->field_alias}
*
* The above will guarantee that you'll always get the correct data,
* regardless of any changes in the aliasing that might happen if
* the view is modified.
*/
?>
<?php print $output; ?>Create a new file in your theme directory that matches the naming convention and copy the default contents into it. Click on the "Rescan template files" button below the list of options. If everything is working correctly, your newly created theme file will be bold in the list, representing that its now the template file being used. If it's not, there's a chance you named it incorrectly.
In my example, I wanted to show the teaser view of a field and then append a "read more" link to the content. I replaced the contents of my newly created theme file with the following:
<?php
// generate the teaser for this field
$teaser = node_teaser($output);
// output the teaser
print $teaser;
// if the teaser if different from the original output,
// show a more link
if ($teaser!=$output) {
print ' ' . l('> Read More', 'node/'.$row->nid);
}
?>











