I am learning drupal and currently working on Views module.I am learning grouping in views.

I have created two groups using views(set format as Unformatted list).I have modified bit of code in theme.inc of views module which is located in modules > views > theme to add class to it.

So HTML output is like:

I want to add number like 1,2,3 etc(depending upon the group created) just beside bottom-box-data-.(Suppose here I have created 2 groups so output should be like bottom-box-data-1 bottom-box-data-2).

Code of theme.ince is :

     * Display a single views grouping.
    function theme_views_view_grouping($vars) {
      $view = $vars['view'];
      $title = $vars['title'];
      $content = $vars['content'];

      $output = '<div class="view-grouping bottom-box-data-">';
      $output .= '<div class="view-grouping-header">' . $title . '</div>';
      $output .= '<div class="view-grouping-content">' . $content . '</div>' ;
      $output .= '</div>';

      return $output;

I know, we need to show some effort then and then some one can help here.But I have no idea from where to start to achieve this.If anyone can help me out, I ll really appreciate it.

Thanks and let me know if more information is required or any one has doubt related to this question.

I came across Drupal SO question, but no one answered to that question yet.


Thanks J. Reynolds for your time and valuable suggestion.

So now I have above function in my template.php and I try to achieve my desired result with grouping levels.

  $grouping = $vars['grouping_level'];//which is 0 for both grouping.

But grouping level always giving 0 for all group hierarchy.

  • 1
    Don't modify code in theme.inc. Correct way is to provide your own theme override in your theme's template.php file. Copy and paste the one from theme.inc to your theme's template.php file, and rename it to MYTHEMENAME_views_view_grouping. Then clear cache. – J. Reynolds Jan 6 '15 at 6:48
  • 1
    Also look at An Intro to Drupal Views Templates and Theming – J. Reynolds Jan 6 '15 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.