User login

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

Resolution

Searched words: 
preprocess_views_view drupal get view as data drupal views2 view data

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.