Training

Our next U.S. stop:

Mike Anello and Andrew Riley from Mediacurrent are teaming up to offer the first Blue Collar Git workshop on Friday, June 8 as part of DrupalCamp Charlotte (also part of the Southeast LinuxFest). The cost is only $149 for the full day if you register during the month of May ($199 otherwise). 

New Podcast

Posted Wednesday, May 9 at 7:50 am
Brandon Morrison (Brandonian on drupal.org) joins Andrew Riley and Mike Anello on the first post-DrupalCon Denver edition of the podcast to talk about all things Geo in Drupal 7. Brandon is one of the maintainers of the GeoField module and is an active member of the Drupal Geo community.
Download Podcast 82
DrupalEasy_ep82_20120509.mp3
Syndicate content

Newsletter

Stay up-to-date on DrupalEasy workshops and other events. On average, we send about one newsletter per month.

Testimonial

Mike is a great teacher!

Who are we?

DrupalEasy is the collective expertise of Ryan Price and Michael Anello, who joined forces to provide training and consulting services worldwide. Read all about them and what they can do.

What is Drupal?

Drupal is a free, super-powerful content management system for sites that require information posting and collection, including blogs, forums, videos, photos, and databases of information. We think it is the best platform available. Here's why...

Why Drupal?

More and more savvy organizations are going with Drupal for content management, and its no mystery why. It’s free, flexible, and easy to maintain for small or large volume sites. Learn more...

Using Display Attachments to Provide a Consistent Summary in Views 2

Average: 4.5 (26 votes)

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.

Trackback URL for this post:

http://drupaleasy.com/trackback/54

7 comments

Anthony wrote 2 years 39 weeks ago

Hi, This is close to what I

5

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.

Guest wrote 2 years 51 weeks ago

Thanks, this is very helpful.

4

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.

ultimike wrote 3 years 7 weeks ago

Lavanya, I'm not sure what

Lavanya,

I'm not sure what you mean exactly. Can you provide an example?

-mike

Lavanya wrote 3 years 7 weeks ago

Could you please explain

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

Lavanya wrote 3 years 7 weeks ago

Superb explanation

5

Superb explanation

Lee wrote 3 years 13 weeks ago

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.

Mark wrote 3 years 13 weeks ago

Very interesting, I didn't

Very interesting, I didn't know this functionality existed!

Syndicate content