fromMarch 2011
Article:

Attachments: The No-Muss No-Fuss Views Upgrade

0

As Drupal developers discover fairly early on, you can have a top-class web site without the Views module, but unless you are going to duplicate portions of what it does, your options without it will be limited.

Views gives you many options for gathering content information from one or more sources and presenting it as a cohesive page, often as 'rows' of items on a page such as articles of a particular topic. Within the same view you can also create a block that lists, for example, the five most popular articles from which the visitor can select one to display.

That, for many, is what Views will do for you. It will allow you to present a homogeneous view of one collection of content. It would be a very powerful thing if this were all it does, but as it turns out, it can do quite a bit more.

One of the display options that Views offers is Attachment, and likely one that you have ignored...until now. I promise, in a few minutes it will be one that you never ignore again!

An Attachment display is one that appears along with the primary display (such as Page), but can contain content independent of that in the primary display. Just how independent is completely up to you. Why is this a big deal? Because the two (or more) displays can interrelate, thus improving the user experience and the value of your site!

Let's create an example. For step-by-step instructions, refer to the link in the Resources sidebar .

Our example is based on books and authors. There is one content type for books, and another for authors. The goal is shown in the following image, and includes the following components:

  • Book information – a Views page display
  • Author information – a Views attachment display, with the author based on the chosen book
  • Book selection – a Views block display

This is a simple example. It could be designed with a second block from which to select an author, or with either or both blocks also being attachments. Whatever you thought could be achieved with Views...up the ante!

Resources

The view in this article can be found on the resources page for this article under the Drupal Watchdog heading of the Books and Articles section of J. Ayen Green’s blog, theaccidentalcoder.com