If the view-grid has an attribute containing class, the class is property is printed twice, as in the following HTML excerpt:

<table class="views-view-grid cols-3" class="views-view-grid">

The code responsible for this is in views/theme/theme.inc and views/theme/views-view-grid.tpl.php.

views/theme/theme.inc, line 761:

$vars['class'] = 'views-view-grid cols-' . $columns;

views/theme/views-view-grid.tpl.php, line 16:

<table class="<?php print $class; 

" print $attributes; >
?>

I am guessing there should be a check as to whether the $attributes string contains class, in which case the $class string should not be printed beforehand.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sivert’s picture

Suggested patch: Remove class=" print $class; from template, since $attributes is the default container of class, as I understand it.

dawehner’s picture

Oh removing something is probably bad. People might assume it exists for their custom templates.

what about checking the attributes class in the prepocess or in a process function?

damiankloip’s picture

Do you have exact step to reproduce this? I can't reproduce this at the moment. I agree with #2 though, if we need to fix this, it should be done outside of the template.

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

.

lorisbel’s picture

You can reproduce the bug simple creating a new view and choosing 2x2 grid layout.

lorisbel’s picture

FileSize
622 bytes

Here is a quick patch, please test it. I suggests to remove $attribute againt of $class, because the content of $attributes is included in $class variable.

damiankloip’s picture

As dawehner mentioned in #2, any patches will probably need to be using the process/preprocess functions to manage this instead.

dawehner’s picture

Status: Postponed (maintainer needs more info) » Needs work
+++ b/theme/views-view-grid.tpl.phpundefined
@@ -10,9 +10,9 @@
+  <h3><?php print $title; ?></h3>  <h3><?php print $title; ?></h3>

Also printing the title twice doesn't seem to be what you expect.

treckstar’s picture

I stumbled into this error while validating my site as XHTML. Using Views 3 stable release, Omega Theme, and a lot of other modifications...

Unlike the original post, I was using a Views Table format, and the class was repeated twice.

I solved this quickly by overriding the views template for the table format, and deleted the print $attributes.

I know this is not the most ideal way, but I was not selecting any of the "table" element classes anyways.

Minor issue and easy fix.

fox mulder’s picture

#9: I think so the $attributes variable can contain any other attribute like class, so it's not recommended to delete it. My suggestion is the following code in template.php:

/**
 * $variables['attributes'] does not exist here, we are using $variables['attributes_array']['class']
 */
function YOUR_THEME_NAME_preprocess_views_view_grid(&$variables) {
  $classes = explode(' ', $variables['class']);
  foreach ($variables['attributes_array']['class'] as $attribute_class) {
    if (!in_array($attribute_class, $classes)) {
      $classes[] = $attribute_class;
    }
  }
  $variables['class'] = implode(' ', $classes);
  unset($variables['attributes_array']['class']);
}
dadderley’s picture

Thanks fox mulder.
I am using an Omega subtheme.
This cleared up this annoying problem.