Hi,

Am I doing something wrong? I can't seem to override region.tpl.php for the sidebar_second region (I haven't added any new regions, just using the base ones).

I've put the following in my template.php:

function <mytheme>_preprocess_region(&$vars, $hook) {
  dpm($vars['template_files']);
  $vars['template_files'][] = 'silly';
}

However, filenames of region.tpl.php, region-sidebar.tpl.php, region-sidebar-second.tpl.php, silly.tpl.php don't work. This includes putting the files in <mytheme>/ or <mytheme>/templates/....

The dpm() turns up with region-sidebar, region-sidebar-first, and region-sidebar-second.

Thanks!

Comments

mmilo’s picture

Naming it as block-sidebar_second.tpl.php seems to have worked. For anyone else that may need this, don't forget to copy over block.tpl.php as well.

Oddly enough, if I left it as region.tpl.php the changes showed up on the admin/build/block/list page, but not anywhere else. Why is that?

johnalbin’s picture

Category: support » bug

What the…?

Moving this to a bug report until I get a chance to verify this.

jaarong’s picture

Glad I found this, I'm having the same issue. Trying to create a custom second sidebar region and it will not override using region-sidebar-second.tpl.php. The way I fixed it was moving region.tpl.php and region-sidebar.tpl.php to my sub-theme templates folder. If this is the proper method, it didn't seem that apparent in the docs.

dstotijn’s picture

Title: Cannot override region.tpl.php » Cannot override region.tpl.php / zen_preprocess_region
Version: 6.x-2.x-dev » 6.x-2.0

I think the discussed issue is:
Template overriding not working if base template doesn't exist in subtheme folder. Not a Zen issue, see: http://drupal.org/node/279573

I'm having a different problem:
Overriding the zen_preprocess_region function in a subtheme's template.php file doesn't seem to work. Not sure if this is a bug though or if I'm doing something wrong.

If anybody has an idea, please elaborate :)
Thanks!

dstotijn’s picture

PS. I've managed to add my desired candidate function by adding it after line 85 in template.theme-registry.inc in the array of preprocess functions.

dstotijn’s picture

Version: 6.x-2.0 » 6.x-2.x-dev
johnalbin’s picture

Title: Cannot override region.tpl.php / zen_preprocess_region » Cannot override region.tpl.php

@dstotijn: Preprocess functions are never "overridden". Your sub-theme can add additional preprocess functions that come after Zen's, but they don't prevent zen's from being run. That's how all preprocess functions.

Also, if you have a different problem, open a different issue.

johnalbin’s picture

Status: Active » Fixed

I just committed some code that should make region-REGION-NAME.tpl.php templates work fine in sub-themes.

Please test 6.x-2.x-dev and let me know if it fixes this issue.

jstoller’s picture

Status: Fixed » Active

I just updated to the latest 6.x-2.x-dev and my region-REGION-NAME.tpl.php files stopped working.

jstoller’s picture

It looks like the code to add region template suggestions was removed from zen/template.php in the last dev update. I added the following to my subtheme's template.php file and it seems to be working.

<?php

/**
 * Override or insert variables into the region templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("region" in this case.)
 */
function csc_zen_preprocess_region(&$vars, $hook) {
  // Sidebar regions get an extra template suggestion.
  if (strpos($vars['region'], 'sidebar_') === 0) {
    $vars['template_files'][] = 'region-sidebar';
  }
  // Setup the default template suggestion.
  $vars['template_files'][] = 'region-' . str_replace('_', '-', $vars['region']);
}

?>

On a side note, I find it curious that a placeholder theme_preprocess_region() function isn't included in the default template.php file. Was this done intentionally? If so, what is the reasoning?

barraponto’s picture

Status: Active » Fixed

I have just made some tests, and I noticed that adding region-REGION-NAME.tpl.php to the sub-theme templates folder works, but just as any other template file, you must have the base template file in the folder.

Also, from what I read on zen_preprocess_region in template.php:494, the template suggestions are being properly loaded.

johnalbin’s picture

It looks like the code to add region template suggestions was removed from zen/template.php in the last dev update.

The code was converted. Inside zen_blocks(), region template suggestions are now implemented as "theme hook suggestions" (a pattern in d7 that replaces d6's "template suggestions").

Status: Fixed » Closed (fixed)

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