Drupal: Views: how to group fields

aneuryzm picture aneuryzm · Feb 2, 2011 · Viewed 24.3k times · Source

I've created a views of node and I've selected the "fields" option in order to select which fields to display and in which order.

Is there a way to group such fields ? It would be very useful to have parent divs in my html code.

thanks

Answer

Mark picture Mark · Aug 1, 2012

There's a simpler way to do it: http://www.arsnova.cc/web-development-articles/2012-07-27/grouping-fields-together-drupal-views

Let's say you want to group fields 1-3 together within a div.

  1. First, exclude fields 1 and 2 from display. (By "exclude", I do not mean to delete them from the views display; rather, click on the "exclude from display" button within each field's options.) The fields you exclude from display must come before the other field for this to work. If they don't, rearrange them so they do.
  2. Go to field 3, and rewrite the results, inserting the token for each of fields 1-3.

That's all you need to do. Fields 1, 2, and 3 will now appear within field 3's div. If you want, you can also add additional markup within the "rewrite results" area.