3

How do I make sure ALL regions are wrapped according region.tpl.php?

In a subtheme of Zen I have created my own regions and modified the page.tpl.php file to something like the following:

<div #page>
    <?php print render($page['header']); ?>
    <?php print render($page['content']); ?>
    <?php print render($page['footer']); ?>
</div>

Some of the regions get a region wrapper from region.tpl.php, others get the code from no-wrapper.tpl.php (no wrapper). How can have all regions receive a wrapper?

1

From the code it looks like Zen adds that template suggestion in zen_preprocess_region(), but only to the content region:

elseif ($variables['region'] == 'content') {
  // Allow a region-specific template to override Zen's region--no-wrapper.
  array_unshift($variables['theme_hook_suggestions'], 'region__no_wrapper');
}

If you're editing the Zen theme directly (which you shouldn't be :P) just remove those 4 lines; if you're creating a sub-theme, implement your own region preprocess function, copy the code from Zen's, and leave those lines out:

function MYTHEME_preprocess_region(&$variables, $hook) {
  // Sidebar regions get some extra classes and a common template suggestion.
  if (strpos($variables['region'], 'sidebar_') === 0) {
    $variables['classes_array'][] = 'column';
    $variables['classes_array'][] = 'sidebar';
    // Allow a region-specific template to override Zen's region--sidebar.
    array_unshift($variables['theme_hook_suggestions'], 'region__sidebar');
  }
}
2
  • Thank you Clive, but the content region is still receiving the wrapper code from no-wrapper.tpl.php. Sep 18 '12 at 15:18
  • Did you clear Drupal's caches since making the change?
    – Clive
    Sep 18 '12 at 15:24
1

To avoid region-content blocks from receiving the block--no-wrapper.tpl.php template, go to template.php in your sub-theme and unquote or add the final function:

function zen_expeditiedokter_preprocess_block(&$variables, $hook) {
    if ($variables['block_html_id'] == 'block-system-main') {
        $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
    }
}

This will give the block.tpl.php template to the content region (without editing the Zen main theme) and thus avoiding the no-wrapper.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.