API page: http://api.drupal.org/api/drupal/modules--system--region.tpl.php/7
Describe the problem you have found:
Don't yet know if this
region-specific (region-*.tpl.php) overrides not consistent -- some work, some don't
http://drupal.org/node/1200196
is a code, or documentation, bug. In any case, not working as advertised.
Comments
Comment #1
_________ commentedmoving this over from the Forum post, as I'm fairly convinced this is a bug, rather than just usage,
to repeat ... i'm trying to get the D7's region overrides working.
if in my (fusion) subtheme's 'page--front.tpl.php' I have
<? php print render($page['header']); ?>
, and in 'region--header.tpl.php' I simply add
i'd expect to see "BLAH BLAH" displayed on my front page. atm, it's not.
a similar addition to a copy of 'region.tpl.php' in my subtheme, otoh, DOES get changes picked up & displayed.
further, add'ns to region--page_top.tpl.php DO get picked up, but additions to region--page.tpl.php &/or region--page_bottom.tpl.php do NOT ... even tho html.tpl.php contains:
if I add something to 'region--page_top.tpl.php', changes ARE picked up & displayed. but,
if I add same changes to 'region--page_bottom.tpl.php', changes ARE *NOT* picked up & displayed.
so, not exactly consistent behavior
@ region.tpl.php, works
@ region--header.tpl.php FAILS
@ region--page_top.tpl.php works
@ region--page_bottom.tpl.php FAILS
reading @ http://api.drupal.org/api/drupal/includes--theme.inc/function/template_p... suggests
"... Uses the region name to generate a template file suggestions ..."
iiuc, implies (verified @ http://drupal.org/node/1200222) that one should use 'region--(region_name).tpl.php' for overrides.
but, i've now tried each of:
region-(region_name).tpl.php
region--(region_name).tpl.php
region_(region_name).tpl.php
region__(region_name).tpl.php
Only some, not all, for the second case, 'region--(region_name).tpl.php' are working.
fyi, yes i'm clearing theme registry @ each page load; both set in Devel module, and with 'drush cc all'.
finally, yes, region names are in my theme's .info file,
and, my theme folder contains a region.tpl.php, needed for any of region--(region_name).tpl.php to work,
Comment #2
_________ commentedComment #3
tim.plunkettI can reproduce with clean install of 7.2, using Bartik.
Comment #4
tim.plunkettI thought I had blocks in my header region, but it was just Bartik's user account/logout menu. So maybe not a bug?
So template_preprocess_region only runs if the region has blocks placed in it?
Comment #5
good_man commentedOne simple question, did you add any content to that region (header)? drupal doesn't render empty region, so it doesn't see any preprocess & templates for that region.
Comment #6
tim.plunkettWith help from amateescu and chx, I've confirmed that it's not a bug, just not well documented.
template_preprocess_region() will not run for an empty region, it would need either a block or something added programatically, e.g. hook_page_build().
However, I don't think that any changes need to be made to core docs files, just http://drupal.org/node/1089656. I'll mark this issue as fixed once I do so, hopefully tonight.
Comment #7
_________ commentedyes, for each of the examples i referenced and labelled as "FAILED", i've added content. the same content in every case. namely,
in some cases, as per the OP, it renders. in other cases, it does not.
e.g., added to "region--page_top.tpl.php", it renders. added to "region--page_bottom.tpl.php", it does not.
and, in all cases, i've got the same content in "region.tpl.php" itself which, as posted, DOES render.
Perhaps it's me, but I don't see how that inconsisent behavior could/should either be 'as expected', or simply 'poorly documented'. It IS however, reproducible ... here, anyway.
Comment #8
tim.plunkettAdding markup to a template file is not the same as adding content. Templates are not content.
Essentially, something has to exist in the page render array to be considered content. Blocks are just the easiest example. Adding one block to all regions should make all of your template files work as you expect.
Comment #9
_________ commentedhere's the simplest test i can conceive,
region.tpl.php
region--page_top.tpl.php
region--page_bottom.tpl.php
page source:
Comment #10
good_man commentedI meant by adding content, adding a block from admin/structure/block page, for example add the "Powered by Drupal" to the header region, and then recheck, your template region--header should be loaded (you may need to clear the cache).
Comment #11
good_man commentedComment #12
_________ commentedadding a block to the Header region,
http://imageshack.us/photo/my-images/577/blocksmy.png/
then rebuilding registry, changes to 'region--header.tpl.php' ARE, now, picked up.
why, then, are changes to 'region--page_top.tpl.php' picked up without having added anything to the page_top region, but changes to 'region--page_bottom.tpl.php' NOT picked up?
how, in either case, does one similarly add block content to those page_top & page_bottom regions, both of which are declared in the themes' *.info, per your suggestion/example? note that those regions are not made available in the block admin region pulldown?
does a 'null' block exist out-of-the-box? something that, added to a region to force-enable it's ability to be overridden, but lacking any actual rendered content? or is that something one must create?
Comment #13
tim.plunkettWhat is a region without content? Template files are ideally for markup only, to wrap content generated by PHP. If a region has no content, why would its wrapper be rendered?
Page top and page bottom are special regions, see system_system_info_alter(). If you're using the standard Drupal install, page_top is being populated by Toolbar module, see toolbar_page_build(). That gives page_top content, which forces the region to render, picking up your template.
As far as an empty block to trigger something special in your region, perhaps what you really should be doing is putting that something special into a custom block.
I've added documentation here.
Comment #14
good_man commented@richardofc: nice question, there are two different types of "regions", ones that can be defined by any theme (e.g. header, footer), and they are not rendered unless you put content in them. The second type are system regions (e.g. page_top, page_bottom), they are part of the page, and page will always be rendered no matter what you have inside it, these system *regions* (region is not an accurate name for them) can't be seen in block's admin page.
Comment #15
chinhlc commentedIf region empty. You can use hook_page_alter to $page[$region] run region-*.tpl.php. example:
function THEMENAME_page_alter(&$page) {
// All Region Header
if(!isset($page['header']['#region'])) {
$page['header']['#theme_wrappers'] = array('region');
$page['header']['#region'] = 'header';
}
}
hope help