The phptemplate.engine generates a variable $layout set to one of 4 values depending on whether blocks are enabled iin the standard left and right sidebars and where, the values are 'left', 'right', 'both' or 'none'.
This patch to restrict showing blocks : http://drupal.org/node/80201 seems to have introduced a bug since $layout is now never set to 'none'.
The relevant code is part of the function phptemplate_page in phptemplate.engine:
/**
* Populate sidebars.
*/
if ($show_blocks) {
global $sidebar_indicator;
/**
* Sidebar_indicator tells the block counting code to count sidebars separately.
*/
$sidebar_indicator = 'left';
$sidebar_left = theme('blocks', 'left');
if ($sidebar_left != '') {
$layout = 'left';
}
$sidebar_indicator = 'right';
$sidebar_right = theme('blocks', 'right');
if ($sidebar_right != '') {
$layout = ($layout == 'left') ? 'both' : 'right';
}
$sidebar_indicator = NULL;
}
else {
$layout = 'none';
}
For some reason this else never sets $layout to 'none', I don't know why. The patch removes the else and and defines $layout as 'none' by default – suggestions on better ways to fix this appreciated.
If a theme uses $layout to set css class and id for the various possible layouts it can break if no blocks are enabled in the left and right sidebars.
The patch was made against Drupal-5.1 but it's likely this problem persists in 5.x and 6.x dev since this code block hasn't changed.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | phptemplate_layout_variable_fix-1.patch | 589 bytes | adrinux |
| phptemplate_layout_variable_fix-0.patch | 607 bytes | adrinux |
Comments
Comment #1
adrinux commentedOn #drupal jadwigo suggested moving the definition of $layout out of the if block, so it's set even when $showblocks is false. Which sounds like it might be useful.
Attached is an updated patch that does that.
Comment #2
dries commentedWhile that is nice, I'd _still_ like to understand why the else-clause never triggers. Maybe we're not fixing the root of the problem. Additional investigation seems in order. Thanks in advance.
Comment #3
adrinux commentedWell, I'll take a shot.
The parent function phptemplate_page (line 150 of the Drupal-5.1 phptemplate engine ) passes an argument with a default value for $show_blocks like so:
Within this function our problem if..else statement starts with:
(See further up the thread for the whole if...else).
In other words, if $show_blocks is true execute this code, if false set $layout to 'none'. But $show_blocks is already set to TRUE, and nothing within the function will set it otherwise.
It appears $show_blocks is intended to be set false elsewhere, see for example: http://drupal.org/node/81343 , and http://drupal.org/node/111416 (the latter of which looks like a dupe of this issue) - my patch would of course break that functionality.
I recommend the patch on that dupe http://drupal.org/node/111416 which just adds the default value for $layout back, that fixes this bug without breaking anything else :)
Comment #4
adrinux commentedDuplicate of http://drupal.org/node/111416 which has a better patch too