I want my sidebars to be 4 column and not 3. I'm not seeing a great way to do this right out of the gate... right now I'm changing out items in the page.tpl.php file. What is the best practice to do this for this theme?

Comments

valkum’s picture

The easiest way is to create a subtheme with a changed page.tpl.php
Maybe you could create a feature request to include this into theme settings.

mattsmith3’s picture

@ valkum will do. In the mean time, here's a work-around:

In template.php:

function mythemename_preprocess_page(&$variables) {
  // Add information about the number of sidebars.
  if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
    $variables['content_column_class'] = ' class="col-sm-4"';
  }
  elseif (!empty($variables['page']['sidebar_first']) || !empty($variables['page']['sidebar_second'])) {
    $variables['content_column_class'] = ' class="col-sm-8"';
  }
  else {
    $variables['content_column_class'] = ' class="col-sm-12"';
  }
}

and in page.tpl.php (located in /bootstrap/theme/system/--copied to local subtheme templates folder) you can change you column widths manually like so:

    <?php if (!empty($page['sidebar_first'])): ?>
      <aside class="col-sm-4" role="complementary">
mattsmith3’s picture

netikseo’s picture

Matt, I tried to do as you described and second sidebar becomes 4 columns width, but main content hasn't change into 8 columns, still 9 columns. Any ideas why?
My sub-theme name is "bootstrap_4colsidebar", so I'm using "function bootstrap_4colsidebar_preprocess_page(&$variables) {" Is that right?

I tried to enable both sidebars and then I get regions:
col-sm-4 col-sm-6 col-sm-4, when it should be all col-sm-4

Appreciate your help!

bkno’s picture

Issue summary: View changes

If anyone else couldn't get the preprocess overriding to work (didn't have the time to debug) an alternative is just replacing the section element that relies on $content_column_class in the subtheme's page.tpl:

<section class="<?php if (empty($page['sidebar_first']) && empty($page['sidebar_second'])) { print 'col-sm-12'; } else if (!empty($page['sidebar_first']) || !empty($page['sidebar_second'])) { print 'col-sm-8'; } else { print 'col-sm-4'; } ?>">

I also updated the sidebar widths to col-sm-4.

markhalliwell’s picture

Status: Active » Closed (duplicate)
Related issues: +#2128129: Provide setting to change sidebar/content widths
fdefeyter@gmail.com’s picture

Such a shame we can't change that :-(

BarwonHack’s picture

#5 is perfect - thank you so much bkno :)

pradeepjha’s picture

#2 worked for me.

bcgarland’s picture

In addition to #5 I also had to edit the following in the page.tpl.php file to reflect the changes in column width.

<?php if (!empty($page['sidebar_first'])): ?>

      <aside class="col-md-4" role="complementary">

        <?php print render($page['sidebar_first']); ?>

      </aside>  <!-- /#sidebar-first -->

    <?php endif; ?>

and

    <?php if (!empty($page['sidebar_second'])): ?>

      <aside class="col-md-4" role="complementary">

        <?php print render($page['sidebar_second']); ?>

      </aside>  <!-- /#sidebar-second -->

    <?php endif; ?>

I changed the content class to col-md-8 and sidebars to col-md-4

TheThemerist’s picture

#2 Worked here.
As long as your main column mark-up in page.tpl.php contains:
<?php print $content_column_class; ?>
...It should dynamically update to use the correct bootstrap class depending on 1 or 2 sidebars.
Well at least it has for me.

lunk rat’s picture

Using 7.x-3.x-dev (10/2/2014) I simply copied page.vars.php into my subtheme, then renamed the function function bootstrap_preprocess_page to function mysubthemename_preprocess_page, then changed the $content_column_class logic to suit my column width needs, then changed the col-sm values of both elements in page.tpl.php

Nothing needed in template.php. Just make sure you change the function name in any *.vars.php files that you override in your subtheme.

Anonymous’s picture

I tried copying the logic from bootstrap_preprocess_page(&$variables) into mytheme_preprocess_page(&$variables) and could not get my changes to take effect. Strangely, when I printed out the variables using dpm() it had a record of my change, but it wasn't actually being applied.

My solution was to change the variable name to content_column_width and update it in my page.tpl.php file.

hockey2112’s picture

I wanted my secondary sidebar to be 4 columns, so I edited my page.tpl.php file as such...

I changed this: print _bootstrap_content_span($columns); ">
To this:

and I changed this:
To this:

Is this an acceptable/correct solution? Any issues that may arise from this? I don't plan on using a Primary sidebar.

febdao’s picture

#2 work for me!
Thanks so much!

smlnkv’s picture

#2 works fine for Bootstrap 7.x-3.0 and not work for 7.x-3.x-dev (7.x-3.1-beta2). I used hook_process_page instead of hook_preprocess_page. It works for me