An attachment is an advanced feature of views that is used to create a view that is a secondary display "attached" to a primary display. In this video, I'll show you how to add an attachment to the block display of our Shop view, which will display a list of users and the products they have posted.

  • Go to "Structure => Views => Shop" (admin/structure/views/view/shop/edit/page)
  • Click "+ Add" in the Displays section
  • Click "Attachment"

Title

  • Title
    • Click "Shop"
    • For: This attachment(override)
    • Title: List of Users
  • (Apply(this display))

Format

I’ll change the display format from grid to unformatted list of fields

  • Format
    • Click "Grid"
    • For: This attachment(override)
    • [x] Unformatted list
    • (Apply(this display))
      • Grouping field Nr.1: (author) Posted by (This will group the results according to user name and will render the output as another field)
  • (Apply(this display))

Fields

We'll only be displaying the list of users and product name, so let's remove the other fields.

  • Click the dropdown next to “Add”
  • Select “Rearrange”
  • For (This attachment (override))
  • Click “Remove” next to:
    • Content: Product Image
    • Content: Price
    • Content: Availability
  • (Apply (this display))

Now, the live preview looks a little better, but we have the “Posted by: Brian” at the top and then again next to each product. We can’t remove the field entirely, because we’re using it to group the items, so let’s just exclude it from the display.

  • Click "(author) User: Name (Posted by)"
    • [x] Exclude from display (This will hide the field from the display.)
  • (Apply(this display))

Now, we don’t have the redundant info in our view.

Filter Criteria

We'll be displaying users whether their products are listed as available or unavailable so let's remove the "Filter by Availability" in filter criteria

  • Click "Content: Availability (exposed)"
  • For: This attachment(override)
  • (Remove)

Sort Criteria

Let's sort the display by user name

  • Click "Add" next to Sort Criteria
  • For: This attachment(override)
  • [x] User: Name
  • (Apply(this display))
  • (Apply(this display))

Remove sorting by price

  • Click "Content: Price(asc)"
  • (Remove)

Alright, now our view is setup. Let’s configure the attachment settings.

Attachment Settings

I’m going to attach this display to the "Block" display, and have it displayed below the block display.

  • Attach to
    • Click "Not defined"
    • [x] Block
    • [x] Block
  • (Apply)
  • Attachment position
    • Click "Before"
    • [x] After (This will position the attachment after the block )
  • (Apply)

Now you can decide whether the attachment should inherit the contextual and exposed filters of the display it is attached to. The block display doesn’t have either type of filter, so I won’t change anything, but the option is available here.

Header

  • Click "Global: Text area"
  • For: This attachment(override)
  • (Remove)

Footer

  • Click "Global: Text area"
  • For: This attachment(override)
  • (Remove)
  • (Save) (Save the view)

Now, we can go home and see that the "Most recent products" block has our attachment that lists products that are group by username.

In the next video, we'll explore another use for grouping fields and create a view that groups content by the year it was published to create a yearly archive.