Feeding your views without cluttering your site’s search


Feeding your views without cluttering your site’s search

by Sean Corrales

The Views module is one of the most powerful and useful modules available for Drupal; a veritable swiss army knife able to build pages, interfaces, blocks, and more.  Oftentimes when working on projects, I’ll encounter a block of content such as quotes or logos that need to be displayed in a block. Entering these kinds of content as nodes is the best way to handle this since it makes it easy for non-technical admins to add, edit, and delete items appearing in the node.

Because of the nature of these nodes, though, I don’t want them to be available to regular users outside the context of their block. For example, if you were working on a law site with quotes from clients that randomly were displayed in a Views block, you wouldn’t want those quotes to show up in search results or displayed as individual pages. These nodes exist solely for the purpose of feeding content in the Views block.

So how do you create nodes to feed a block without allowing this content to be viewed out of context? There’s several ways but I’ll be sharing a method I’m particularly fond of. It requires only the CCK module, in addition to Views of course, which makes it lightweight. It also takes advantage of the fact that Views can display unpublished nodes to users who otherwise would not have the privileges to see the content.

Start by creating or editing a content type. The most import thing to do here is make sure under “Workflow settings”, you have unchecked “Published”. We want all our nodes of this type to be unpublished. This will prevent them from showing up in search results or being viewed out of context on their own node page. I refer to these type of nodes as “feeder nodes” because I use them exclusively to feed content into Views. When using feeder nodes, they should always be unpublished.

You will then want to add a new field to your content type. I usually give the field a name of “Active”. It’s a “Text” type and uses the “Single on/off checkbox” operation. For the allowed values, I simply enter “off” for the off state and “on|Active” for the on state. We will use this field as a way for admins to remove items from displaying in a Views block without deleting it; it is a replacement for the “Published” option that nodes regularly use. I recommend naming this field something other than “Published” to prevent any confusion from there being two “Published” fields on the node edit form.

Now you’re ready to create your view. Create the view as you normally would. You’ll want to limit your view to the feeder content type. Under filters, you’ll add the “Active” field that you’ve created. Make sure to select the field that’s labeled with “ – Allowed Values” at the end. This lets you select from the on/off states that you have created. Select the operator “Is one of” and select the on state that you defined earlier.

Now you should have a view that displays your feeder nodes in the context that you intend site visitors to see. The only people who can see these nodes outside of their context is users with the “Administer Nodes” permission. Simply treat the “Active” state as you would the “Published” option on regular nodes.

More About the Author

Sean Corrales

Lead Web Developer
Internet Explorer ignoring CSS files Like most web developers, I do most of my development work in one browser (in my case, Firefox) and then do cross browser checks after ...
Creating checkout panes for Ubercart All code comes from a shipping insurance module I wrote for Ubercart. I plan to release it on ubercart.org and drupal.org after I ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK


Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072


Love our blog? You should see our emails. Sign up for our newsletter!