How do I add an additional sidebar to a Zen sub-theme?
Question
I want to add an additional sidebar to my zen based theme with fixed columns.
I added it to the theme info, and printed it in the page.tpl.php file, but I don't know how to
configure its CSS files to make it look correct; I don't know how to make the content region expand to fill the available space when there is an empty region with no blocks in it like with Zen.
My theme contains 4 columns:
- left sidebar 1 (130 pixels)
- left sidebar 2 (255 pixels)
- content (509 pixels)
- right sidebar (130 pixels)
The total width would be 1024 pixels.
How can I do that?
Solution
You can do it with preprocess function at template.php template. I will write you just one example, and you can adapt it for your needs.
1.At Your template.php template.
function yourthemename_preprocess_page(&$vars, $hook) {
$page = $vars['page'];
// if only left sidebar is present
if ($page['left_sidebar'] && !$page['left_sidebar2'] && !$page['right_sidebar']) {
$vars['class_content'] = t('yourclassforcontentwithsidebar');
$vars['class_left_sidebar'] = t('yourclassforleftsidebar');
}
// if no sidebar is present
if (!$page['sidebar_left'] && !$page['left_sidebar2'] && !$page['right_sidebar']) {
$vars['class_content'] = t('yourclassforfullwidhtcontent');
}
}
You can find more variations here: php logical operators.
2.At your page.tpl.php, at all regions where you want flexible width, put extra class, for example for left sidebar:
<?php if ($page['left_sidebar']): ?>
<div id="left_sidebar" class="sidebar <?php print ($class_left_sidebar);?>" >
<?php print render($page['left_sidebar']); ?>
</div>
<?php endif; ?>