The Views2 Attachment Display

I’ve recently started my first Drupal 6 site and with that, my first exposure to Views2. At first glance, all the available template files and the slick new interface got me excited about the second coming of Views, but then I started working on the views for my site and quickly became frustrated with the new mechanics. I could no longer just write what I needed. So why was it so hard? I simply wanted the first item of data returned to use a larger picture, than the rest of the items. This was my “Featured Item”.

I’ve recently started my first Drupal 6 site and with that, my first exposure to Views2. At first glance, all the available template files and the slick new interface got me excited about the second coming of Views, but then I started working on the views for my site and quickly became frustrated with the new mechanics. I could no longer just write what I needed. So why was it so hard? I simply wanted the first item of data returned to use a larger picture, than the rest of the items. This was my “Featured Item”. Pretty simple right?I’ve recently started my first Drupal 6 site and with that, my first exposure to Views2.

At first glance, all the available template files and the slick new interface got me excited about the second coming of Views, but then I started working on the views for my site and quickly became frustrated with the new mechanics. I could no longer just write what I needed.

So why was it so hard? I simply wanted the first item of data returned to use a larger picture, than the rest of the items. This was my “Featured Item”. Pretty simple right? With the previous Views module, this was easily doable, But now I had no idea how to proceed. My first thought was that I’ll just have to do some reading of the docs and figure it out pretty quickly.

Not so fast.

I dug through the Views2 API and found nothing but frustration. Finally, after two forum posts and patiently awaiting responses on #drupal-support, I found my solution – the Attachment display.

What is this Attachment display? From the API docs, “Attachment displays are secondary displays that are ‘attached’ to a primary display. Effectively they are a simple way to get multiple views within the same view. They can share some information.”
To set this up, just add the Attachment display to your view.

For this example, I needed the attachment to display before the page display, and attached to the page display. Also, I set the attachment to 1 for “items to display”. Now, for the page display, set the “items to display” to 9 with an offset of 1. The offset skips the first item, which is rendered with our attachment display, and Viola, we have our “Featured Item” displayed differently.

So after adding some div tags to some template files for the view, I was good to go. What I really like about this display is that its another view, So the fields that are only needed for my “Featured Item”, do not show up for the rest of the items. With the previous Views module, all my items would have the same fields, and I needed conditionals to decide which fields to display.

Special shout out to Crell on #drupal-support on freenode for the help.

views-attachment-thumb.jpg

views-page-thumb.jpg

Eric McKenna