Hi all,
We recently migrated our World of Warcraft guild website from GuildPortal to our own host. As the designated webdeveloper, I took a well-researched plunge into the world of Drupal. Our site went live about a month ago, and we've continuously been modifying and updating the site since then. You can take a look at the site at TWC Gaming. Our performance optimization and caching still isn't fully set up, so the site is slow on occasion. Apologies in advance.
One of the biggest challenges we faced in this project is theming. We're a community of gamers, and as such, most of us own large monitors with high resolutions. At the same time, we wanted the static content on the site to be high compatible and convenient to not just us but everyone who happens to stroll onto our site. We originally had 1280px fixed-width across the whole site, but the forums ended up too big for some of our users on smaller screens. When we cut it down to 1028px wide, it ended up too small for everyone else. And so we went digging...
You may have noticed that the current iteration of the website has almost all the pages at 1028px wide - with the exception of all the pages with 'forum' node type inside. The forum pages use a variable-width setup, and given the layout of Acquia Slate, that was quite a challenge to accomplish. We do like the theme a lot and we decided to put up with the extra work and keep the looks.
So long story short, I wanted to post here and give some information on how to accomplish this on Drupal 6 and Acquia Slate because the few tickets asking the same questions I had on this subject didn't have any responses to it.
1) First and foremost, Acquia Slate (at least the version we're using - without Fusion or Skinr) doesn't inherently have the capacity to apply different templates based on node-type. There's a useful Drupal document about how to get this done, and the gist of it is simply pasting the following code snippet inside the theme's template.php, under the phptemplate_preprocess_page(&$vars) function.
<?php
if ($node = menu_get_object()) {
$vars['node'] = $node;
$suggestions = array();
$template_filename = 'page';
$template_filename = $template_filename . '-' . $vars['node']->type;
$suggestions[] = $template_filename;
$vars['template_files'] = $suggestions;
}
?>Simply put, this allows for creation of page-'nodetype'.tpl.php files where nodetype is the type of node you want to apply a unique template to. For our purposes, this was page-forum.tpl.php.
2) Once that was done, we made a copy of page.tpl.php and renamed it appropriately for our node type. Inside this tpl.php file, there are several div tags with corresponding ids. The ones that we decided to modify are, for the most part, self-explanatory. There are others, but these were the ones that had to have the variable width. Everything else remains static.
- "page"
- "header-wrapper"
- "content"
- "content-wrapper"
- "sidebar-first" and "sidebar-last"
These same IDs are used by other tpl.php files as well so changing them is out of the question. We simply created new ones on their place. Our naming convention, in this case, is "page-fluid", "header-wrapper-fluid" "content-fluid" and "content-wrapper-fluid". We didn't change the sidebar-first and sidebar-last, because the sidebars are still static content.
3) With the page-forum.tpl.php properly edited, the last step was to actually go into the theme's style.css file and add these three new div id's we created. Acquia Slate has three different possible sidebar/content layouts though, and because of that, there are three different sets of content-wrapper-fluid in the new style.css. "sidebar-first" and "sidebar-last" were both individually modified for the entire website. Below are the specific changes we made:
/* Layout
-------------------------------------------------------------- /
#page-fluid {
margin: 0 auto;
min-width: 1040px;
max-width: 1440px;
position: relative;
min-height: 1500px;
}
/ Header regions
-------------------------------------------------------------- /
#header-wrapper-fluid {
background: #fff;
background-image: url('images/header-left.png'), url('images/header-right.png');
background-repeat: no-repeat;
background-position: top left, top right;
height: 33px;
margin: 0 10px 25px 10px;
overflow: hidden;
padding: 26px 20px 32px 20px;
position: relative;
}
/ Sidebar regions
-------------------------------------------------------------- /
#sidebar-first {
position: absolute;
left: 0;
}
#sidebar-last {
position: absolute;
right: 0;
}
/****************************************/
/ COLUMN LAYOUTS /
/ /
/ Classes for different column layouts /
/ that are applied to the <body> tag. /
/****************************************/
/ Single column layout
* main content
-------------------------------------------------------------- /
body.layout-main #content-wrapper-fluid {
padding: 0 10px 0 10px;
min-width: 1040px;
max-width: 1440px;
}
/ Two column layout
* sidebar | main content
-------------------------------------------------------------- /
body.layout-first-main #content-wrapper-fluid {
margin: 0 10px 0 250px;
width: 100%;
float: right;
}
body.layout-first-main #content-fluid {
border-left: 1px solid #590000;
margin: 0 0 0 280px;
padding: 0 0 0 10px;
min-width: 740px;
max-width: 1140px;
}
/ Two colum layout
* main content | sidebar
-------------------------------------------------------------- */
body.layout-main-last #content-wrapper-fluid {
margin: 0 250px 0 10px;
width: 100%;
float: left;
}
body.layout-main-last #content-fluid {
border-left: none;
border-right: 1px solid #590000;
margin: 0 280px 0 0;
padding: 0 10px 0 0;
min-width: 740px;
max-width: 1140px;
}We don't use the sidebar | content | sidebar system anywhere on the website, but following the same logic, that section isn't hard to modify either. After all of these were done, we simply cleared our cache and our forums settled nicely into a stable, variable-width layout.
This approach isn't without its downsides.
For one, making the white banner variable width requires splitting the .png file into two and putting whitespace in the middle. The CSS code that makes this happen under "header-wrapper-fluid" is CSS3 and as of now, it is not supported by IE8 or Firefox 3.5 or older (3.6 supports it). Google Chrome, Apple Safari and Opera all work with this convention though.
Another unfortunate workaround is likely born out of my own lack of knowledge. I am self-taught in the ways of HTML, PHP and CSS. I tried various methods of making the website variable width - methods that work elsewhere on non-drupal websites - but the only one that worked for our particular situation is the one above. It's not elegant. It uses "position: absolute;" to stomp right over the area taken by #content-wrapper, and the only way we made this work was to squeeze the content-wrapper in with a margin, equal in size to the sidebar that we're trying to make room for. In addition, because the sidebar is now separated from the page with "position: absolute;", the gray background can actually be too short on occasion when the length of the content is less than the length of the sidebar. We prevented this by adding "min-height" to the #page div so that the gray background is extended down at a minimum of 1500px from the top of the page. Again, not so elegant.
The solution is far from perfect, but we did spend weeks on research (with no results) and a few days on top of that just experimenting on possible solutions on local installations of the site. My hope is that it at least serves as a good starting point to anyone who struggled with this same issue on their own installation.
Cheers!
Comments
Thanks for the writeup
I'm new at Acquia, working on improving the basic CSS of our themes and I found this writeup really helpful. Thanks for taking the time to put it together.
Absolute positioning to get sidebars in place is a totally legit strategy, but as you discovered, you need to manage container heights of the abs positioned elements because their size collapses.
Another approach is floating, but you probably found that your sidebar wouldn't float to the right side of your forum. The trick to get this in place is to put the sidebar above the forum div in the structure and the forum will wrap around the sidebar just like text around an image. But how do you get the form to remain a nice rectangle and not wrap around or behind the sidebar? Apply overflow:hidden to the forum container and it'll snap into place. Or you could float the forum left and set it's width, the sidebar's width and all left/right padding/margin widths in percentages so that they equal or are less than 100%.
Anyway, thought I'd offer some strategies to you to play with. The site looks great though and it works, so at the end of the day, perhaps there's no need to muck with it!
Just curious, but what made you guys settle on Acquia Slate?
Thanks Jesse :) We're pretty
Thanks Jesse :) We're pretty happy with the site itself too - although our host (iPage) uptime and database performance is terrible.
I messed around with the floating approach a lot and you're right that the sidebar wouldn't float to the right (and instead it would be pushed below the forums). I never thought about shifting the divs in the structure though. It is printed after the content in the forum.tpl.php file. It just never occurred to me that might be the problem. Go me and my lack of experience. We're going to be migrating to a new host soon anyways so perhaps I'll go and play with it. There's a nice simplicity to floating layouts. It allows us to set up percentage margins and things just fall into place automatically depending on the min/max page width. Certainly eliminates the necessity to micromanage container sizes individually. The advice is greatly appreciated.
Our choice of Acquia Slate was actually accidental - although we're pretty happy with how it turned out. When the site first went up, the priority was simply getting the functionality to our users. As an online community, we're very attached to our forums and any sort of downtime on it deprives us of a critical medium of communication. So we initially just browsed the Drupal theme list and picked something that was visually appealing. It was supposed to be temporary. The modifications to the theme came later, once all the content was up there, and we decided to stick with Acquia Slate as the "base" theme just because it was already on the site to begin with ;)