Hi,
Sometimes I would like to override an entire view with my own HTML and then just loop out all the data in there.
Let's say I have a view block called "recent_articles", then I'd set up a views-view--recent-articles--block.tpl.php.
My question is, what's the easiest way to get a hold of all the (raw) data the view is providing me? I don't want to have to override both views-view, views-view-list, views-view-fields etc etc, I would just like to keep this one view in one file and handle _everything_ from there.
I've found that a lot of the times this variable contains most of the fields I've checked in the view:
$variables['view']->result[0]
But sometimes it doesn't. I would really love it if I could just get an associative array of _all_ the raw data the view is spitting out so that I can do whatever I want with it.
Is this possible?
Regards
Edit: If I print_r() $variables['view'] there's a gazzillion things in it and it seems almost impossible to just get an array of the raw data.
I'd just love something like all the rows in $rows with each $row containing each $field like $field['title'], $field['description'] etc etc.
Thanks
Comments
A couple of thoughts Have you
A couple of thoughts
Have you looked at the semantic views module?
You might consider writing a display plugin.
I've only briefly looked at
I've only briefly looked at the semantic views module. I'd prefer not keeping such information (HTML) in the database though. I would very much like to keep my HTML in template-files.
Is the only way to accomplish what I want to write my own SQL-queries and assign my own variables? Views is really easy and nice to use but overriding all those templates becomes a chore when you have to do it for each and every view you create.
views_get_view_result()
I think I've found what I'm looking for.
A function called views_get_view_result() allows me to only get the results of the view as an array of objects. It's actually _exactly_ what I need but unfortunately it doesn't work as I'd hoped.
The problem with it is that it doesn't seem to return any CCK fields.
I've got a CCK field in one of my node types called something like "related_nodes" which holds a list of related nodes.
Using the view normally I get a list of those nodes but if I use views_get_view_result() all I get is the node which has the related nodes. I get none of the actually related nodes. Which is exactly what I really need.
Do I have to use node_load in order to a hold of the related nodes as well?
Views relationships
You should be able to set up the views relationships to get at your referred nodes.. then add fields from those nodes' types. Now your result should include that data.