Getting Views as Data with Drupal 6 Views 2
Is there a standard way to get views as data? (to count the rows and such) or is it expected that this will be done in the preprocess functions, and views methods always return themed output?
Kathleen worked around this by making changes directly in the theme's views-view.tpl.php
.
Alternatively,
<?php
function pdtheme_preprocess_views_view__contributions(&$variables) { //...
?>
should let you see the variables. see if $rows exist, and in theory decide how to output from there.
This can be defined as above in template.php, or views preprocess functions can also be defined in a module; see Views API or if still not working this thread).
Finally, it seems virtually undocumented, but it is possible to call a view in such a way as to get the data relatively directly.
[8:55pm] ben-agaric: Is there a standard way to get views as data? (to count the rows and such) or is it expected that this will be done in the preprocess functions, and views methods always return themed output?
[9:39pm] merlinofchaos: benjamin-agaric: $view->execute but beware that raw data may not be all data since some data is created via extra queries and is only available from the rendered fields.
[9:40pm] benjamin-agaric: thanks merlinofchaos ... that's the one i had my eye on but instead of just trying it was working backwards through the code to see how the arguments get in, heh
Stefan did it this way:
<?php
$my_content_view = views_get_view('manage_my_content');
$my_content_view->set_arguments(array($user->uid));
$my_content_view->build('page_2');
$my_content_view->execute('page_2');
?>
And a really useful page on this and more:
http://groups.drupal.org/node/10129
Comments
Post new comment