This template is used to print a single grouping in a view.

It is not actually used in default Views, as this is registered as a theme function which has better performance. For single overrides, the template is perfectly okay.

Variables available:

  • $view: The view object
  • $grouping: The grouping instruction.
  • $grouping_level: Integer indicating the hierarchical level of the grouping.
  • $rows: The rows contained in this grouping.
  • $title: The title of this grouping.
  • $content: The processed content output that will normally be used.
1 theme call to views-view-grouping.tpl.php

File

theme/views-view-grouping.tpl.php
View source
<?php

/**
 * @file
 * This template is used to print a single grouping in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $grouping: The grouping instruction.
 * - $grouping_level: Integer indicating the hierarchical level of the grouping.
 * - $rows: The rows contained in this grouping.
 * - $title: The title of this grouping.
 * - $content: The processed content output that will normally be used.
 */
?>
<div class="view-grouping">
  <div class="view-grouping-header"><?php

print $title;
?></div>
  <div class="view-grouping-content">
    <?php

print $content;
?>
  </div>
</div>

Comments

jonaskills’s picture

How would I use this template as a single override? For a specific view?

Thanks!

TarKHaoS’s picture

As Bagz said, standard Drupal templates names overrides are also working with this one.
views-view-grouping--MACHINEVIEWNAME.tpl.php for a specific view
views-view-grouping--MACHINEVIEWNAME--MACHINEDISPLAYNAME.tpl.php for a specific display of a specific view

Bagz’s picture

According to https://api.drupal.org/api/views/theme!theme.inc/group/views_templates/7 All views templates can be overridden with a variety of names, using the view, the display ID of the view, the display type of the view, or some combination thereof. This means you can use views-view-grouping--myviewname.tpl.php for a view with machine name "myviewname".

bbinkovitz’s picture

Why is it that this override only works if there are two or more grouping fields? I would expect this to work with any number of grouping fields.

scotself’s picture

I am so glad I saw your comment here. I was struggling with this until I saw it. I found, after some digging, it seems that this template only kicks in at level 2 for backwards compatibility reasons. Basically, any view built and themed previous to the addition of a second level of grouping and this tpl file would break, so the first level is still at the views-view.tpl.php file level. A really clear example of this is tables that are grouped. The grouping for those actually happens in the views-view-table.tpl.php; the grouping is rendered as each grouped table's element. There may be more to it than this, but I believe that's the underlying reason for the decision and how this works.

onepartscissors’s picture

Thank you for your note here. This about killed me too. ✊🏼