Page not found blocks/sidebars

In Drupal, when you get a 404 page all your blocks are hidden which rather sucks as it blows your theme. This function added to your theme's template.php file saves the day.


/**
* Override or insert variables into the page templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("page" in this case.)
*/
function phptemplate_preprocess_page(&$vars, $hook) {
$vars['path'] = base_path() . path_to_theme() .'/';
$vars['logo'] = preg_replace('@^'. base_path() .'@', '', $vars['logo']);
// handy helper for themes, not related to 404 issue
$vars['base_path'] = base_path();
// Only does the check if required
if(!$vars['show_blocks']) {
global $theme;
$regions = system_region_list($theme);
foreach (array_keys($regions) as $region) {
// Only set left and right regions
// Drupal core sets the other blocks already
// IMHO this shows a real lack of design considerations for leaving these out!
if ($region == 'left' || $region == 'right') {
$blocks = theme('blocks', $region);
if(isset($variables[$region])) {
$vars[$region] .= $blocks;
}
else {
$vars[$region] = $blocks;
}
}
}
}
}

Your blocks should now be back on the page.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.