As you can see from below the H3 tag which is generated from using grouping (@ Format: Unformatted list | Settings:Grouping field) has no divs around it like the regular fields. In my case I would like to wrap some HTML around it but I can't see where. On the fields it's easy, just override the output with what you want but on this generated group title I haven't found how to do this so any help will be much appreciated.

  <div class="view-content">
    <h3><a href="/blogs/83" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Internet Department</a></h3>
    <div class="views-row views-row-1 views-row-odd views-row-first views-row-last">
      <div class="views-field views-field-picture">
        <div class="field-content">


Reg’s picture

It looks like it's a matter of overriding the views template views-view-unformatted.tpl.php . Is there another way or is this it?

dawehner’s picture

Status: Active » Fixed

Even overriding a tpl doesn't help as this is not themable at the moment.

There is an issue #477338: Multiple group: group by more than one field which would allow you to theme that.

Reg’s picture

Status: Fixed » Active

Thanks for that, I think that issue is a little more complex than my needs however now seeing that it's an issue even for one group I'm thinking a little more creatively.

Have you ever considered using a view within a view as a solution? Perhaps it will put a wrapper around the inner view so we have some way of distinguishing what's group from a major heading. If so, in theory you can have an unlimited number of views in views so that may solve the issue of groups within groups as well.

dawehner’s picture

Status: Active » Fixed

Well you could try to use the views_field_view module, but it's probably kind of hard to get the groupby working with it.

Reg’s picture

If you do it correctly you won't need group by. In the parent view you make a simple list by what you would normally use as a group by and pass the value as an argument to the child view. Use the passed parameter to limit the results in the child view and you are mimicking a one to many relationship in the database. You should be able to do this to as many levels as you like barring any limitations in the module.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

stephen Piscura’s picture

Status: Closed (fixed) » Active


I'm dancing around with views grouping fields with strange results. I have a users view that creates a "staff" page with these fields:

  • Username
  • Image (image field on user entity)
  • Bio (long text field on user entity)
  • Title (authored-by-user relationship: title of node)
  • Subtitle (authored-by-user relationship: text field on node)

If i choose to group by username, the grouping gets surrounded by an H3. I then exclude this field from display so that it doesn't display in both the grouping andinterior fields. But if i follow the same logic by adding the bio field as a second grouping field, then it gets the H3 and the username becomes a simple div. Obviously wrapping a long text field in a H3 is not what i want to do. What i ultimately want is something like this:

<img>image of user</img>
<p>user bio</p>
<p>posts by user</p>

I don't know how to build the kind of views parent/child relationship using contextual filters which you've described. Can you help me and others understand how this works?

Reg’s picture

I think the answer is I use a module called "views_field_view" ( not contextual filters. Have a look at that module and see if it will do what you want.

stephen Piscura’s picture

Thanks for your reply Reg,

I was hoping to solve my use-case without an extra module, but if i absolutely cannot, then i'll definitely look into Views Field View.

RogerRogers’s picture

Category: support » bug

Personally, I think this could use a basic fix: Honor the HTML tag setting of the field that the grouping is based on ('Grouping field nr.N').

All the functionality is there, including the ability to override the content, change the surrounding tags, etc. If the grouping setting just used the related fields settings this would be a breeze. I also think this would naturally be expected (at least I anticipated this would be the default behavior).

dawehner’s picture

Component: Documentation » Code
Category: bug » feature

There are problems with doing this automatically

  • This would break all existing groupby views, because people never expected to work like that
  • You have to make it configurable based on the first argument
travis-cunningham’s picture

If you change the format to HTML list and select a grouping field it gives you options to add classes to the wrapping element as well as the list and the list parent.

jlongbottom’s picture

I just created a template file that overrides for only that one view and changed the H3 to an H2

Danny Englander’s picture

I just ran into this issue as well. It was a simple matter of switching the display to Semantic Views (you'll need that module to do this) and then change the "GROUPING TITLE > Element" to h2. I don't think this is really an issue with Views, it's a themer's task to solve things like this (i.e. #13 above using a template file is a good example as well). Views gives you what are reasonable defaults but it can't anticipate every possible scenario and use case for a themer and a design.

damien_vancouver’s picture

I solved this problem using the solution in #13 of overriding the views template file in my custom theme.

I can confirm that it does work despite the comment in #2. You must override the views style template for your currently selected style (I used unformatted list so that is the template I describe). Here are the exact steps I used.

1. Copy the views-view-unformatted.tpl.php template file from sites/all/modules/views/theme and place it in your theme's templates folder.

2. Figure out the machine name of your view. Mine was called products_by_category. One way to see this machine name is to edit the view and then look at the URL in your browser address bar. It will contain the machine name: admin/structure/views/view/products_by_category/edit

3. Rename the template file you copied in step one to have your view name after --. So I renamed mine to: views-view-unformatted--products_by_category.tpl.php so it would only override for this particular view.

4. Edit the template file and adjust the line displaying the title to use whatever you want instead of h3. I made mine use a <div class="category-description"> instead of the <h3>:

<?php if (!empty($title)): ?>
  <div class="category-description"><?php print $title; ?></div>
<?php endif; ?>

5. Save everything and clear your site caches.

6. Now when you load your view it should use the new overridden template and your group field will have the markup you want.

giorgio79’s picture


I don't think this is really an issue with Views, it's a themer's task to solve things like this

That's why Views should not be adding h3 tags to every group 2 level...

Views adds h3 tags for both HTML List and Unformatted list for group 2. Group 1 gets no heading at all it seems.

One can already provide custom style settings for a field. Views should use that instead of this hardcoded h3...

dawehner’s picture

Just in case someone is interested, I opened a feature request against Drupal 8.

giorgio79’s picture

awesome, here is the ref #1880100: Allow to configure the h3 element for view style plugins

Just peeked at your post tracker dawehner. Wow, you're doing a massive amount of work. A thread updated around every 10 minutes :)

dawehner’s picture

The drop is always moving!

joakaune’s picture

I just encountered the same problem.
And I can't for the life of me understand the logic behind views adding a random h3 tag in the middle of everything.
It makes no sense at all, and just creates extra work since you have to create a workaround.
Please remove the h3 tags and make everything unformatted unless you add custom style settings to it.

HAg’s picture

The solution in #15, works in version 6.x too.

imperator_99’s picture

Solution in #15 works perfectly. I changed the H3 to H2 and it all works beautifully. Should not have been an issue at all though - views really should allow you to select the style for the grouping fields just as it does for other fields, as giorgio79 suggested.

Abelito’s picture

#13 worked for me!

prairiebean’s picture

#15 perfect fix for Grid style as well.

aagd’s picture

#15 (damien_vancouver) So easy! Thanks for the instructions. With this custom template I could also add an extra div wrapper around the list to simplify placing on a susy grid.

sanjadmin’s picture

Thanks. Post #15 worked for an html list presented in a block. In my case I am using an html list view so my filename is views-view-list--rss_block.tpl.php.

ladybug_3777’s picture

Issue summary: View changes

There is a themeable function that you can override to style the group however you want. Simply use this function in your template.php file in your theme: (This function originally comes from within the view module)

function YOURTHEMENAME_views_view_grouping($vars) {
  $view = $vars['view'];
  $title = $vars['title'];
  $content = $vars['content'];

  $output = '
'; $output .= '
' . $title . '
'; $output .= '
' . $content . '
' ; $output .= '
'; return $output; }
scotself’s picture

Am I crazy, or does this (the theme function above, as well as the views-view-grouping.tpl.php file) only work if you have multiple levels of grouping? I suppose that's because of dawehner's comment about breaking backwards compatibility?

scotself’s picture

So a nice little trick I just figured out:

1) Set the grouping field to the same field for level 1 and 2

2) Remove this chunk from your views-view-style.tpl.php file (copy it to your theme and modify there)

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>

This removes the grouping markup for level 1

3) Copy the views-view-grouping to your theme and go nuts. You can (probably want to, unless you want to modify all groupings) rename to target just the view you're working on (views-view-grouping--view_machine_name--display_id.tpl.php or the like). If you're ok with targeting the way ALL groupings are rendered, the theme function that @ladybug mentioned should do the trick too.

In fact, I created a views-view-grouping--view_machine_name--display_id.tpl.php, which worked great, but then I tried a preprocess function named MYTHEME_preprocess_views_view_grouping__view_machine_name__display_id(&$vars) but it didn't work. I tried getting less specific, like just MYTHEME_preprocess_views_view_grouping__view_machine_name(&$vars) but to no avail. Only the MYTHEME_preprocess_views_view_grouping(&$vars) works from what I tried:

function ltl_preprocess_views_view_grouping(&$vars) {
  $vars['title'] = 'Group ' . $vars['grouping_level'];

Finally, note that there is a known bug that is being worked on, where $vars['grouping_level'] is always 0 to the template from the preprocess function above. #1488744: Grouping level is always zero in views_plugin_style::render_grouping_sets() has a reasonable approach to handle in your theme and patches underway.

scotself’s picture

Also, while I'm here, any ideas how to get a count of the groups? I don't see any way to do so at first glance...

andrezstar’s picture

#15 +1 cool

Dima DD’s picture

Regarding formatting titles of the 1-st (outmost) grouping level in multi-level grouping case, my solution: I've used firebug and noticed that they have css class="view-grouping-header". This class is used in views-view-grouping.tpl.php (and in as well). So I've simply declared this class in vews.css (just for testing) and set desired font setting there, and now my 1-st level titles looks great.