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

_________’s picture

Title: region-specific (region-*.tpl.php) overrides not consistent -- some work, some don't » Documentation (code?) problem with region.tpl.php suggestions
Priority: Major » Normal

moving 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

 <div>BLAH BLAH</div>

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:

 print $page_top;
 print $page;
 print $page_bottom;

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 ..."

...
$variables['theme_hook_suggestions'][] = 'region__' . $variables['region'];
...

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,

grep ^region ./sites/www.mysite.com/themes/my_fusion/my_fusion.info
 regions[sidebar_first]     = Sidebar first
 regions[sidebar_second]    = Sidebar second
 regions[header_top]        = Header top
 regions[header]            = Header
 regions[main_menu]         = Main menu
 regions[preface_top]       = Preface top
 regions[preface_bottom]    = Preface bottom
 regions[content]           = Content
 regions[postscript_top]    = Postscript top
 regions[postscript_bottom] = Postscript bottom
 regions[footer]            = Footer
 regions[node_top]          = Node top
 regions[node_bottom]       = Node bottom
 regions[help]              = Help
 regions[page_top]          = Page top
 regions[page_bottom]       = Page bottom

and, my theme folder contains a region.tpl.php, needed for any of region--(region_name).tpl.php to work,

ls -1 ./sites/www.mysite.com/themes/my_fusion/templates/*region*
 region--header.tpl.php
 region--page_top.tpl.php
 region--page_bottom.tpl.php
 region.tpl.php
_________’s picture

Title: Documentation (code?) problem with region.tpl.php suggestions » region-specific (region-*.tpl.php) overrides not consistent -- some work, some don't
Component: documentation » theme system
Priority: Normal » Major
tim.plunkett’s picture

I can reproduce with clean install of 7.2, using Bartik.

tim.plunkett’s picture

Title: Documentation (code?) problem with region.tpl.php suggestions » region-specific (region-*.tpl.php) overrides not consistent -- some work, some don't
Priority: Normal » Major

I 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?

good_man’s picture

One 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.

tim.plunkett’s picture

Title: region-specific (region-*.tpl.php) overrides not consistent -- some work, some don't » Region-specific (region-*.tpl.php) overrides do not work for empty regions
Assigned: Unassigned » tim.plunkett
Category: bug » task
Priority: Major » Normal

With 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.

_________’s picture

yes, for each of the examples i referenced and labelled as "FAILED", i've added content. the same content in every case. namely,

<div> BLAH BLAH </div>

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.

tim.plunkett’s picture

Adding 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.

_________’s picture

here's the simplest test i can conceive,

region.tpl.php

<?php
?>

<div> BLAH BLAH </div>

region--page_top.tpl.php

<?php
?>

<div> BLAH BLAH top</div>

region--page_bottom.tpl.php

<?php
?>

<div> BLAH BLAH bottom</div>

page source:

...
</head>

<body
	id="pid-node"
	class="html front not-logged-in one-sidebar sidebar-first page-node sidebars-split font-size-12 grid-type-fluid grid-width-16 fluid-100"
	 thmr="thmr_10">

<div> BLAH BLAH top </div>

<div id="page" class="page">

	<div id="page-inner" class="page-inner">
	</div>
</div>

</body>
</html>
good_man’s picture

Assigned: tim.plunkett » Unassigned
Category: task » bug
Priority: Normal » Major

I 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).

good_man’s picture

Category: bug » support
Priority: Major » Normal
_________’s picture

adding 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?

tim.plunkett’s picture

Status: Active » Closed (works as designed)

What 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.

good_man’s picture

@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.

chinhlc’s picture

Issue summary: View changes

If 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