This was so easy to do in D6, now I am trying to get up to speed using Drupal 7. I have been going at this for hours but can't seem to find a way to manually print fields from a view into a custom view page.

In D6 I used to create a views template,
for example: views-view-fields--video--block-1.tpl.php

Then in there I would give my custom css wrap around the field code like this

Now when in Drupal 7 I try to put in the new views template, I get an error:
Notice: Undefined variable: fields in include() (line 52 of /templates/views-view--message-post--block.tpl.php).
Notice: Trying to get property of non-object in include() (line 52 of /templates/views-view--message-post--block.tpl.php).

Does anyone know how to bring over the fields manually

Comments

WorldFallz’s picture

I'm not sure about how the syntax has changed, but just do a print_r (dsm if you use devel) on the $fields array to see the structure.

shadcn’s picture

Under theme settings in Views UI, look for the Row style output. (NOT style output). $fields variables is not available in Style Output.

krymp’s picture

Thanks Arshad, that was it, I was using the wrong theme file.

What is a quick way to see all the fields names without having to go through the Views UI?

I tried using this but my page comes up empty after I add it in.

 print_r($fields) 

I also use devel, but don't know what the shortcut is to add it in.

shadcn’s picture

The devel function is dsm().

dsm($fields);
andrew smith’s picture

...so how do I print 'title'?

<?php
print $fields['title']->content;
?>

?

langweer’s picture

To print the title of the view you can use

print $view->get_title();

At least, that works for me to get the title of the view printed via the template.

MtnMn’s picture

I'm have the same problem. I have the file: views-view-unformatted--products.tpl.php.
In that file I have: print $fields['field_product_exterior_width']->content;

Once saved and uploaded my view gets the errors:
Notice: Undefined variable: fields in include() ....
Notice: Trying to get property of non-object in include() ....

This should be easy but I have been on this for days.

Thank you in advance

Prancz_Adam’s picture

Hi Ariel,

I have the same issue. Have you find any solution for this?

rodpal’s picture

copy this code in your template to see available data in your view

<?php
dsm($fields)
?>
WorldFallz’s picture