Using Display Attachments to Provide a Consistent Summary in Views 2

The "summary" list is Views is a really handy feature, but unless it is properly configured, it can lead to an inconsistent experience for end-users. The goal of this post is to demonstrate how a little bit of configuration can provide a very consistent user experience.

Here's a quick example of what I'm trying to avoid: consider the following content type called, "Food":

As you can see, it is a very simple content type, with only a single added field, "field_food_type". This text field is set up to require the user to select one of its options.

When creating a view to show all "Food" nodes, there might be too many to display all at once - you'd like to break up the view by food type in order to allow the user to drill down to the food they're looking for. Using a single Views 2 "Page" display, this is easy to do - just add an argument for the food type and have it display a summary when no argument is present:

This will result in the showing only the food types when the page is displayed with no arguments:

When one of the food types is clicked on, you'll see a list of matching foods:

This works great and is easy to set up if this is what you're looking for. However, I find that often I'd like the summary and a listing of matching content to be displayed at all times. When there is no argument present, then I want a paged list of all the content as well as the summary. When an argument is present, I want the filtered content but I still also want the summary. This can be quite easily done using a display attachment.

The first thing you're going to want to do is to set up your "page" display. It will still utilize an argument (since we still want the filtering), but when no argument is present, we want to "display all values":

Next, you need to set up a new display - an "Attachment" display:

The only thing you need to change in this display is the argument settings. First, click on the existing argument and click the "Override" button so we're not overwriting any default values. Next, change the "Action to take if argument is not present" to "Summary, sorted ascending".

Now, at this point we'll only see the summary on the page when no argument is present - but we want to see the summary all the time, regardless of if the argument is present.

This next little bit is the "secret sauce" in the process. You need to change the validation of the argument so that it always fails for the attachment. Then, you can change the "Action to take if argument does not validate" option to "Summary, sorted ascending". To ensure the validation always fails, simply change the "Validator" to "PHP Code" and enter "return FALSE" into the text area:

These settings ensure that the argument validation will always fail, therefore the summary will always be displayed. I also set the summary style to "unformatted" and selected "Display record count with link" and "Display items inline" to complete the setup of the summary.

The final step is to actually attach the new attachment display to the main page - do this in the "Attachment settings" section:

When you're done, you should have the summary and list on the main (argument-less) page:

as well as on any of the filtered pages:

There have been some nice articles written about the usefulness of display attachments - check these out to get some additional ideas of how you might use them.

Comments

Excellent! I've just spent the last few days unsuccessfully trying to do much the same thing using a tab for each group of items. This will work much better. Thanks.

Submitted by Lee (not verified) on Sat, 02/14/2009 - 08:57

Superb explanation

Submitted by Lavanya (not verified) on Sat, 03/28/2009 - 05:33

Could you please explain about displaying 2 Summary values + all values

Submitted by Lavanya (not verified) on Sat, 03/28/2009 - 08:09

Thanks, this is very helpful. Your method helped me to create an alpha-pager for a view that accepts two arguments. The attachment view is set to inherit arguments, and the argument relevant to the alpha pager (article title, in my case) is set up with your "return FALSE;" method.

Submitted by Guest (not verified) on Thu, 05/21/2009 - 18:22

Hi,

This is close to what I want, but does anyone have any ideas how to do an alpha "range"... i.e. something like on encylopedias where each "volume" has "Aar - Alt" to say what that volume covers. I'd like a pager that would have the volume titles as links. Does that make sense at all?

Thanks,
Anthony.

Submitted by Anthony (not verified) on Fri, 08/14/2009 - 04:35

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name