views

Introducing Views Cache Bully: You're gonna cache your views, and you're gonna like it.

views cache bully admin settingsTucked away under the Views UI's "advanced" fieldset is a too-seldom-used option: Views caching. It allows you to cache the query results and/or rendered markup for any given view. This can drastically improve your site's performance.

Unfortunately, many people don't use this option. Maybe they don't know about it, maybe they've forgotten about it, or maybe they don't like. Well, the Views Cache Bully module is here to say "Too bad. You're gonna cache your views, and you're gonna like it."

To quote Dave Stoline (dstol):

Programmatically render a Drupal view with exposed filters, arguments, etc.

Embedding a view programmatically is not too difficult, but what about passing it a value for an exposed filter? This snippet gives a simple example of how to modify the View object in a more meaningful way before rendering it.

Demystifying Views API - A developer's guide to integrating with Views

Learning to use the Views module from the front end of Drupal is a daunting task, but you can rest assured that many others struggle along with you. There are many tutorials and screencasts dedicated the the subject. Tackling the Views API from the backend, however, is a bit more of a challenge. It's not easy to document the behemoth that is Views, and hence, the documentation is limited.

This blog post is the first of a series that will explore the Views API from the backend-- from the code. Clearly, it's not going to be possible for me to give examples of all the various ways that you can integrate with Views. My goal is to provide you with a general understanding Views, and to give you the same tools that I use to tackle the beast. Namely, a methodology for figuring things out on your own. If you're a developer looking to integrate your module with Views, or if you'd like to build custom Views handlers for your site, then stay tuned.

Escape Views' replacement patterns

Views replacement patterns are great, but they take up valuable variable real-estate. If you need to literally output "[nid]" rather than the value of its corresponding replacement pattern, you might start hitting your head against the wall.

I found this issue to be particularly annoying when using the Prepopulate module, which required CCK field names (with bracketed arrays) to a URL.

Never fear! Rather than using "[nid]" in your views text, try using percent encoding rather than literal brackets. The result would be:

%5Bnid%5D

Using percent encoding with stop views from replacing the replacement pattern with a dynamic value.

Downgrading from Views 6.x-3.x-dev to 6.x-2.x

You may notice that after downgrading, you receive and error like:

Unknown column 'view_php' in 'field list' query:..sites/all/modules/views/includes/view.inc on line 1722.

If so, backup your database and then run this mySQL query:

ALTER TABLE views_view ADD is_cacheable tinyint;
ALTER TABLE views_view ADD view_php blob;

Worked for me!

Apart from that, be sure that you've clear all of the Header, Footer, and Empty Text fields from all of your views.

Drupal View: shows teasers of all menu children for current node

I tossed around a lot of strategies for accomplishing this, and in the end I managed to find a module that does most of the hard work for me.

Goal

To create a node which displays the teasers of all its menu children (other nodes nested under current node's menu entry).

Views Accordion - Opening a specific row with a link

Goal: create link that goes to a new page and opens a specific accordion drawer.

Using the Views Accordion module in combination with a little custom code accomplished this. Here's a step by step guide.

Create your view

-add this header with input filter "php code":

Customizing the filefield format in views

Often times, you may want to customize the appearance of a views field, or perhaps add a bit of logic to the output. You can customize the display of any field in Views by utilizing the Views Customfield module.

Here's an example of how to breakdown a basic cck fieldfield into its constituent parts.

<?php
//print var_export($data, TRUE);  //prints out all available fields in view

$value = $data->node_data_field_document_field_document_fid; //relevant fid