Using Views (version 1) in Drupal to get to data

Lately, I have been involved with several projects that required some custom PHP coding. Anyone that has worked with Drupal for length of time knows about the awesome Views Module. It is the query builder for Drupal, all through the web GUI. Views 2 is even better but this blog deals with Views 1. The Views Module allows the embedding of view output into any page by the following code:
$view = views_build_view('embed', views_get_view('view_name'), array ($sArgument), 0, NULL, 0, 0, NULL);
This will return HTML that you can put anywhere. The first argument to this function is the key; it can be any one of the following: page,block,embed and items. Now I really like the last one because the Views module, out of necessity, creates a very noisy HTML output. It is noisy so that the module can handle all the different options without having any HTML or CSS naming collisions. Unfortunately, this output is too busy for me. I have themed a couple of views outputs and I wasn't overly excited with the results. So looking back at that first argument, *items*. If you use that argument, it will return an array. One of the elements of that array is *items*. With this array, you can now do several things very easily. You can use this array, add data to it and re-theme it using your own theme_ function. You can use this array to load nodes and then theme. But here is the cool part that gets around the limitation of Views 1: you can use this array as arguments to feed another view!!
Submitted by davea on Tue, 2009-02-10 23:07. categories [ ]