views:

445

answers:

2

Basically I want to create a php code in my template (views-view-field--body.tpl.php) that would say the following...

if [body] print [node_view] endif

A: 

Off the top of my head and at first look it seems like you are using fields. If it is so, if you look at views-view-field.tpl.php, the comments specify:

  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}

thus you could do something like

if ($row->{$field->body}) { 
  print $row->{$field->view_node}
}
zerolab
Why the braces around $field->field_alias?
theunraveler
I believe this - http://stackoverflow.com/questions/1147937/php-curly-brace-syntax-for-member-variable - will answer your question
zerolab
A: 

What I did to do this was download Views Custom Field and then use this code for the value:

<?php 
if ($data->node_revisions_body) { 
 echo '<a href="/node/' . $data->nid .'">view</a>';
}
?>
Erik