Agaric Design Collective

Getting Views as Data with Drupal 6 Views 2

Average: 3.7 (3 votes)
By Benjamin Melançon
on 30 Mar
0 comments

Key words and phrases

preprocess_views_view drupal get view as data drupal views2 view data

Tags

Description

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

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.