In Drupal 6, I was able to use a Row Style Fields template and create variables to arrange and print later i.e.:

foreach ($fields as $id => $field) {
  if ($field->label == "Phone") {
    $f_phone = $field->content;
print "<h2 class='content'>${f_phone}</h2>\n";

Then I was able to use the variable $f_phone in other places in the template. This does not work in Drupal 7. I am instead getting variable not found errors.

How would I do this in D7?

  • it depend what means 'other place' if you want print it out somewhere outside the row - it's impossible, because it's a template of a single row. You can do whatever you want with the field within the row, not outside. – Jack-PL Jun 19 '13 at 21:28

I figured I would reply to this question since I figured out an answer. Don't know if this is the best way, but it works.

If you use the views-view-fields.tpl templates, you can skip the loop and directly list and style your fields ie:

print $fields['title']->content; 
print $fields['field_location']->content; 

**the code above is inside your php tags

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.