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
Very interesting, I didn't
Very interesting, I didn't know this functionality existed!
Excellent! I've just spent
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.
Superb explanation
Superb explanation
Could you please explain
Could you please explain about displaying 2 Summary values + all values
Lavanya, I'm not sure what
Lavanya,
I'm not sure what you mean exactly. Can you provide an example?
-mike
Thanks, this is very helpful.
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.
Hi, This is close to what I
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.