views2

"More" Link's URL for a Block Display in Drupal6 Views2

It is only available in the top-level theme as a variable, but in case you need to derive the same value from the View object, per se, here it is:

$view->display[$view->current_display]->handler->get_path();

Drupal: 'Views2 Returns Zero Results but SQL Is Fine' Problem

This has happened couple times, already, so I may as well blog about it. If you use Views in Drupal, you already know that it shows you the final SQL generated. Very useful feature, but there's a rare edge condition when the SQL returns results (if you run it from an SQL client), but Views shows zero elements. Extremely frustrating and confusing.

How can this happen?

The thing is, Views omits limit condition when displaying the SQL, so when you copy/paste your SQL in a client you are not running exactly the thing that Views displays.

Solution: check the pagination setting in the View settings. Most of the time the problem is an offset value indicated that is higher than number of elements in the result-set.

Drupal: Expose a Custom Field to Views2

Disclaimer: Views2 Advanced Help contains a more detailed and comprehensive documentation on the same subject. However, that also means that you have to actually comprehend more :) This is just a quick sample code of one usage of the hook_views_data() to expose custom fields from a custom table to Views2. If you need more advanced functionality, do refer to Views2 documentation.

Let's say we are building a small job posting board and, for whatever reason, decided to store all resume-related extra fields in a table called "resume", instead of using CCK. Now we need to expose those fields to Views, to use all the beauty and flexibility of the automated query generation provided by Views.

Let's write a custom module called resume (or add it to an existing module).

The very first thing you need to do when you implement Views hooks is to tell Views that you are doing so and (optionally) - where your inc file will rely that holds all views hook implementation routines. We do that using hook_views_api(). Assuming your module is called "resume" and that you want to put views hook implementation file in the "views" subfolder:

function resume_views_api() {
  return array(
    'api' => 2,
    'path' => 
   drupal_get_path('module', 'resume') . '/views',
  );
}

If you omit the "path" argument, you will have to create the modulename.views.inc file in the root folder of your module (or "includes" subfolder). If you do indicate path - you create it on that path.

Let's create resume.views.inc file (under the "views" fubfolder of the resume module's folder, in our case) and enter following code in it:

Syndicate content