I've been using a sub-theme of Zen (that I created) without any problem using 6.x-1.0

I use Views (pages and blocks) in several places, and style the div items using views Style: Unformatted from the Views panel.

The problem is that when I updated to Zen 6.x-2.x-dev, all instances where I use views, those div items don't display the styles!

So for example, the file modules/acquia/views/theme/views-view-unformatted.tpl.php:

<?php
// $Id: views-view-unformatted.tpl.php,v 1.6 2008/10/01 20:52:11 merlinofchaos Exp $
/**
 * @file views-view-unformatted.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes[$id]; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

When using zen 6.x-1.0 or another theme like Garland, the array $classes is not empty and prints the styles for that item. However, as soon as I use and enable Zen 6.x-2.x-dev the array $classes is empty and no styles are printed, leaving style="" for that item/div. Meaning I can't style those items.

ps. Look at attached images

- style I get with older zen or Garland enabled:
- style I get with zen 6.x-2.x-dev enabled:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

harcher’s picture

Assigned: harcher » Unassigned
harcher’s picture

I managed to find which php line is causing this.

In the template file here, sites/all/themes/zen/template.php. The function zen_process:

/**
 * Override or insert variables into templates after preprocess functions have run.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered.
 */
function zen_process(&$vars, $hook) {
  switch ($hook) {
    case 'page':
    case 'maintenance_page':
      $vars['body_classes'] = !empty($vars['body_classes_array']) ? implode(' ', $vars['body_classes_array']) : '';
      break;
    default:
      $vars['classes'] = !empty($vars['classes_array']) ? implode(' ', $vars['classes_array']) : '';
      break;
  }
}

It's the line:
$vars['classes'] = !empty($vars['classes_array']) ? implode(' ', $vars['classes_array']) : '';

When I comment this line out, the $classes array prints the styles normally from views.

Not sure what to do now!

hadsie’s picture

That's correct that that line is the problem. I would recommend changing it to something like:

$vars['zen_classes'] = !empty($vars['classes_array']) ? implode(' ', $vars['classes_array']) : '';

You'll then need to edit your .tpl.php files so that instead of the $classes variable they use $zen_classes.

thisgeek’s picture

Component: Miscellaneous » PHP Code
Issue tags: +template.php

I have the same issue. Not yet sure how to fix it, but it seems pretty clear that this is an issue with the theme php, so I'm updating the component.

thisgeek’s picture

If the classes_array is empty, should classes simply be set to itself? If so the line might be

$vars['classes'] = !empty($vars['classes_array']) ? implode(' ', $vars['classes_array']) : $vars['classes'];

I suppose that's redundant, but I only meant to clarify my question.

Doesn't seem right. My spider sense is tingling.

harcher’s picture

Thats exactly what I did and its been fine ever since, no problems.

thisgeek’s picture

This issue has also been reported here: http://drupal.org/node/604318

JohnAlbin’s picture

Priority: Normal » Critical

Crap. :-p That's very un-good.

JohnAlbin’s picture

Title: Zen theme and views - views does not display item styles » Views classes are missing from $classes variable
Status: Active » Fixed
FileSize
9.42 KB

Ok. So, the underlying problem is that Zen 2 is inconsistently dealing with template classes. In Zen 1, we only had $classes and $classes_array, but only for the templates that Zen core has. The exception is that page.tpl has $body_classes and $body_classes_array variables.

In Drupal 7, all templates will have a $classes_array available to it in its preprocess function; the $classes variable is not available to preprocess functions. And the $classes_array will be flattened to a string and put into $classes during the "process" function.

In other words, to modify the classes for a template, use the $classes_array variable in the THEME_preprocess_HOOK function. If, for some reason, you need to alter the flattened $classes string, you'll need to do that in THEME_process_HOOK.

So, I think Zen 2 will need to emulate the D7 methodology. Which means we need to add $classes and $classes_array to all templates and not those in Zen core.

What this means is that you won't be able to see or alter the $vars['classes'] variable in your theme's view's preprocess functions. Instead there will be a $vars['classes_array'] array you can manipulate.

I tend to explain things densely when I talk D7 stuff. I've been working with it for a while now! :-) Please ask questions if you don't understand.

Here's the patch that I just committed to 6.x-2.x-dev that should accomplish the d7 match-up and fix this bug all in one go.

JohnAlbin’s picture

JohnAlbin’s picture

FileSize
1.25 KB

Bah. The fix I attached to #9 is insufficient. Some Views tpls have a $classes variable that is an array. You'll need this additional patch to fix it.

Or you can just wait for 6.x-2.x-dev to be updated in ~8 hours.

Status: Fixed » Closed (fixed)

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

jstoller’s picture

Is this documented anywhere? I just spent hours trying to figure out why my theme was going screwy when I added a class to $vars['classes'] in my theme_preprocess_page() function. After stumbling onto this issue, I instead added it to $vars['classes_array'] and everything seems to be working, but finding this was mostly dumb luck.

JohnAlbin’s picture

Its documented at the top of page.tpl.php.