Printing classes for a theme depending on sidebar
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
// our own hook to remove sidebars from admin pages, not relevant here
if (arg(0) == 'admin') {
$vars['sidebar_right'] = '';
}
// layout for body classes
$vars['layout'] = '';
$layout = '';
//Is there a left sidebar?
if ($vars['sidebar_left'] != '') {
$layout = 'sidebar-left';
}
//Is there a right sidebar?
if ($vars['sidebar_right'] != '') {
$layout = ($layout == 'sidebar-left') ? 'sidebars' : 'sidebar-right';
}
if ($layout != ''){
$vars['layout'] .= ' ' . $layout;
}
break;
}
return $vars;
}
?>
And if you want to see everything that's going on, this can be thrown in before the return statement, or at the top, to see what's there before you mess with it:
<?php
global $user; if ($user->uid == 1) drupal_set_message('<pre>'. var_export($vars,TRUE) .'</pre>');
?>
(Internal Agaric note: Instead of a note to remove if we truly never use left sidebars, which we do not, we just link here on how to put this more complex code back.)
Comments
Post new comment