Sunday, February 17, 2008

Layouts Wire Frame Editor

Introduction

This is the third in a series of articles on 3 columns. In the second article I said that you have to perform 4 steps to convert a 2 column template in to a 3 column one. However, I did not explain the 4th step, which is the tweaking of the Layout Editor. Let's see how we can do it.

This blog itself uses a Denim template customized in to 3 columns. You probably have noticed it already. For the purpose of this article, I will use the Wire Frame Editor of this blog as an example.

The Layout Editor

When you click on the Layout tab of your Blogger console, the default view is the Page Elements view. This is where you see the Add and Arrange Page Elements heading and you can use the drag-and-drop feature of the editor to rearrange your page elements.

Here's the default view of the Layout Editor.


All is well until you add your third column using the first 3 steps described here. But the moment you add your third column the Layout Editor gets skewed and some times you find that you can't even edit your first sidebar.

This is how my editor looked like immediately after adding the third side bar to the right of the existing sidebar.


This is not a desirable situation. There's little meaning in adding a 3rd column if you can't add page elements to it, isn't it?

How can we correct this? The answer lies in the body#layout CSS selector. Remember the ID selectors we discussed in the previous article? The body#layout is another ID selector but limited to the scope of the body element. However, we can do without a detail understanding of this selector.

Page Structure Tweaks

Usually the Blogger template has a section called the "Page structure tweaks for the layout editor wireframe". This is found right at the end of the skin of your template. (Some templates don't have it. For example, the default Denim template didn't have one)

This is where the body#layout selector is used to define the layout of our template for the wire frame editor. The notation seems a bit cryptic but this is what it does.

The main purpose of the "Page structure tweaks" section is to define the widths of the various wrappers (the components of the template skeleton) in our template. The best way to explain is to use an example.

Here's the tweak I added to my modified 3 column template.

/** Page structure tweaks for layout editor wireframe */

body#layout #outer-wrapper,
body#layout #content-wrapper,
body#layout #header,
body#layout #footer-wrapper {
width: 760px;
}

body#layout #main-wrapper {
width: 400px;
}

body#layout #sidebar-wrapper {
width: 150px;
margin-left: 10px;
}

body#layout #sidebar-wrapper-two {
width: 150px;
}

The first rule in this part tells the Layout Editor to use a width of 760 pixels for the outer, content, header and footer wrappers. (In the Denim template header is used instead of a header-wrapper). The actual width of the modified template is 1000 pixels. When the Layout Editor uses the actual width, we end up with the skewed Layout Editor that we saw above. Using this tweak we can ask the Layout editor to use a width that is less than the actual size. In other words, we tell the editor to use a scaled down version of our template.

Scaling down the outer wrappers is not sufficient. We have to do the same for the child containers (i.e. main and sidebar wrappers). The main-wrapper in my modified template is 504 pixels and the sidebars have widths of 240 and 200 pixels respectively. Those 3 add up to 944, which is more than the 760 we gave for the outer wrappers. So we define proportionately (this proportion can be approximate) smaller widths of 400, 150 and 150 for the main, first sidebar and the second sidebar respectively. Now they add up to 700 and therefore fits within our scaled down wife frame.

That's all to it. The finished result is shown below.


Note: You might have to do a little bit of trial and error with your particular wire frame editor to get it right. Adjust the widths of the various elements few times until you get it right.

Saturday, February 16, 2008

Adding a Third Column

Introduction

The standard Blogger templates are two column templates. One of the most frequently asked questions on the Blogger forums is "How can I add a third column to my blog?" Many bloggers want to have a third column because that gives more room above the fold, to play around with widgets.

This is the second in a series of articles on 3 column templates. In the previous article, I explained the basic skeleton of a Blogger template. If you are not familiar with the many wrappers (outer, content, sidebar etc.) in your blog template, I strongly suggest that you read it first.

This is not a step-by-step guide on how to modify a given Blogger template in to 3 columns, but this will give you the confidence to modify one, on your own. Trust me, once you finish reading this, you will feel pretty much comfortable with the idea of 3 column templates. (I'm afraid it's a very long post though. It could not be made any shorter)

2 Columns

First let's take a look at the normal scenario. A stripped off version of a 2 column template, with the basic page elements highlighted, is shown below.


This is the skeleton of your template. Of course, you don't see it because the sections are not highlighted as you see in this instance. Since a detailed discussion of this skeleton and the div elements that make up it was given in the previous article, I will not focus on the body element of the template here. Instead, we will dig a little deep in to the Cascading Style Sheet (or CSS) behind the skeleton.

The styling and the layout of the page elements such as the main post area and the sidebar are controlled using CSS rules. For example, it is a CSS rule that tells the browser to place the sidebar to the right of the main post area and not to its left. All the style sheet rules of a template are found inside the skin element of your template. Open your template in the Edit HTML mode and search for the string <b:skin> and scroll down. You will see something like the code given below.

#outer-wrapper
{
width: 682px;
}

#header-wrapper
{
width:660px;
}

#content-wrapper
{
width: 660px;
}

#main-wrapper
{
width: 410px;
float: left;
}

#sidebar-wrapper
{
width: 220px;
float: right;
}

#footer-wrapper
{
width: 660px;
}


(I have taken out some properties from the actual CSS of the skeleton page. The full page can be seen here. If you want to see the full CSS, right click on the previous link and save the page to your disk. Then open it using a text editor such as the Notepad)

The header-wrapper, content-wrapper and the footer-wrapper (yellow boxes in the figure), all have a width of 660 pixels. (i.e. 660px). Because I wanted to highlight the outer-wrapper (the gray box), I have given it a padding of 10 pixels. Hence the width of the outer-wrapper, the grand container which surrounds all other wrappers, has a width of 682 pixels (i.e. 660 + 20 pixels for the left and right padding + 2 pixels for the borders of child wrappers). Note, however, that a real template does not have this padding and therefore outer-wrapper will also have a width of 660 pixels.

Each of the sections in the above code snippet are called id selectors in CSS jargon. An id selector starts with a hash (#) character, then has some string id, followed with a set of rules enclosed within an open brace ( { ) and a closing brace ( } ).

Don't worry too much about it, this is what you need to know about it. When a browser find an HTML element that has the id property set to some id, it will search whether it can find a matching id selector from the CSS rules applicable for the HTML page. In our case, the HTML element is one of the div elements in the body section and the CSS rules are the ones defined in the skin of the blog template.

Consider the <div id="content-wrapper"> element. This div element has the id content-wrapper (note the absence of the # character) and when the browser finds this div, it will look for an id selector that looks like #content-wrapper. If an id selector is found, the style rules defined inside that id selector will be applied to the div. All the other div elements are also styled the same way.

Confused by now? Then take a break, read the first article and come back again.

Adding the Third Column

Now let's get down to the real job. We will take our 2 column skeleton and convert it in to a 3 column skeleton that has two sidebars on the right side. (For a 3 column template with left and right sidebars, look at the fourth article in this series.)

Before you convert a template in to 3 columns, you need to decide where to put the 2nd sidebar (i.e. whether you want the both sidebars to the right of the main post area or whether they should be on the left and right of the main post area). Having sidebars to the left of the post area can delay the loading of posts, as the page elements load in a left to right order. However, its up to you to decide where to put it.

Another important thing you must do is to check whether your template uses images in the header, footer and the background. Templates such as TicTac and Rounders do use images and therefore you need to do additional work to customize them. Minima and Denim, on the other hand, don't use images and therefore are easy to modify.

In this article, we will only focus on modifying templates that do not use images. I will later explain how to modify a template that does use images.

The Steps

You have to perform 4 steps to convert a 2 column template in to a 3 column one.
  1. Add a new id selector for the 2nd sidebar wrapper.
  2. Introduce a new div element, as a child of the content-wrapper, to be the placeholder for the 2nd sidebar
  3. Expand the width of the parent wrappers to accommodate the new sidebar
  4. Modify the CSS rules for the wire frame Layouts editor
First step is to add a new CSS id selector. Just copy and paste the existing id selector named #sidebar-wrapper (some Blogger templates just call this #sidebar) and rename it to something like #sidebar-wrapper-two.

The changes we do to the template skin are shown in red below.

#sidebar-wrapper
{
width: 220px;
float: right;
}

#sidebar-wrapper-two
{
width: 220px;
float: right;
}


The second step is to introduce a new div element to the body of the template. We place this div after the div for the first sidebar, as a child of the content-wrapper. The additions to our template are shown below.

<div id='content-wrapper'>
<div id='main-wrapper'>
<p>Main</p>
</div>
<div id='sidebar-wrapper'>
<p>Side Bar</p>
</div>
<div id='sidebar-wrapper-two'>
<p>Side Bar Two</p>
</div>
</div>

In the actual Blogger template, you have to copy the div and the <b:section> element as well.

After we complete the first two steps, our skeleton page will look like this.


Our skeleton looks a bit crammed, isn't it? Now what's wrong here? We just inserted the 2nd sidebar but we never provided room for it inside the parent wrappers. Therefore the sidebar we just added gets pushed down. (The full code for this crammed 3 column skeleton is available here)

When we complete step 3, this problem will be solved. We have to provide space for this new sidebar inside its parent container. Since we just copied from the existing sidebar, the 2nd sidebar also has a width of 220 pixels, the amount by which we should expand the parent container, content-wrapper.

#content-wrapper
{
width: 880px;
}


We increased its width to 880 (i.e. 660 + 220) and the result is shown below.


Oops! What happened? Increasing only the content-wrapper is not sufficient. Then our blog looks skewed. To balance out, we have to expand the header-wrapper, footer-wrapper and the grand parent, outer-wrapper by the same amount. Add 220 to all of them.

#outer-wrapper
{
width: 902px;
}

#header-wrapper
{
width: 880px;
}

#footer-wrapper
{
width: 880px;
}


Before we look at the result, there's another catch that I have to explain to you.

The existing sidebar is, by default, floated to the right. (Floating is the means by which we decide the positioning of page elements relative to other elements. We don't have to discuss it in detail here.)

In this example, we will float the new sidebar to the right of the existing sidebar. To keep the original sidebar on the left, we have to modify its float property to left. (In the Blogger templates, the two variables $startSide (which is by default left) and $endSide (which is by default right) are used instead of the actual values 'left' and 'right'). So that change is:

#sidebar-wrapper
{
width: 220px;
float: left;
}


When we do all this, we have the following 3 column skeleton template.


There it is! What you have been waiting so far. (Thank you for your patience if you read this long post this far). Starting from a 2 column skeleton, we modified it to a 3 column template with 2 sidebars on the right. The one in dark blue is the new sidebar.

Wait a minute. I didn't tell you about how to modify the wire frame editor, did I? No, I will not discuss it here as that will stretch this article even more. See this article to find out how to do that.

Summary

So in summary, we learned about
  • the skeleton of a 2 column template
  • how CSS rules are hooked up to the page elements through id selectors (Note, however, that there are many other types of selectors in CSS)
  • how to add a 3rd column to your Blogger template
  • how floating can be used to position the sidebars
If I managed to make you feel confident about changing in to 3 column templates, then I have achieved my objective. I would love to hear your feedback.

(Note: All the skeleton HTML pages used in this article are available here)

Thursday, February 14, 2008

Skeleton of a Blogger Template

Introduction

All the standard templates available on Blogger consist of only two columns; a main column where all your blog posts appear and either a left or a right sidebar where you can put various widgets such as About boxes and AdSense units.

2 columns are somewhat limiting with respect to the amount of content you can have above the fold. (i.e. in the area above the bottom edge of your browser that is readily visible without having to scroll down) If you can squeeze in an additional 3rd column, that gives you more room to play around with.

This article will explain the basic skeleton of a Blogger template and will lay the foundation for my next article Adding a Third Column. If your are comfortable with things such as outer-wrapper and content-wrapper, then you can skip this article and read the next article straight away. If not, I strongly suggest that you read this first.

The Skeleton

Before you do any changes to your template, you need to understand its basic structure. The key to being able to modify your template is to know how it is made up.

The skeleton of a Blogger template is made out of div elements, the magical generic container element of HTML. I used the word magical because of the amazing flexibility offered by the div element with respect to the layout of a website. You will see how flexible it is to change the layout of a blog using the div elements and a little CSS, in the next article.

The figure below shows the main compartments of a template.


As you can see, outer-wrapper is the highest level container that encompasses every thing else. Think of it as the grand parent of all the containers in a given blog and it is shown in a gray shading in the above figure. Next level, or the first level child elements (if I'm to use a technical term), consists of 3 containers. They are, from top to bottom, the header, the content and the footer wrappers and are shown in yellow. The light blue boxes are the lowest level of (or the inner-most) containers, and they form the main posts area and the sidebar. Those two are the grand children in this family of containers.

So that is the skeleton or the framework of your template. But we will take a look at a little bit of HTML to get an idea of how this is done in the code. (Don't worry, it isn't that hard)

A Stripped Off Template

Given below is a stripped off, minimalistic version of the body element of your Blogger template. When we take out all the widgets, sections etc. this is what we get. (The full HTML page, including the CSS styles, can be found here)

<body>
<div id='outer-wrapper'>
<div id='header-wrapper'>
<p>Header</p>
</div>
<div id='content-wrapper'>
<div id='main-wrapper'>
<p>Main</p>
</div>
<div id='sidebar-wrapper'>
<p>Side Bar</p>
</div>
</div>
<div id='footer-wrapper'>
<p>Footer</p>
</div>
</div>
</body>

Remember the div element which I mentioned above? The skeleton you see in the above snippet is made entirely out of div's. For each of the wrappers, there is a matching div and the grand parent outer-wrapper is the outer-most div. The others are nested (i.e. included within the <div> and </div> tags of its parent) according to the containment hierarchy we saw in the above figure.

The following screen shot shows how this skeleton page will render on a browser window.


Do you now see it? Your blog, too, has all these boxes. But they are invisible, because in a website, you don't usually highlight the div elements as I have done in the skeleton page. I have applied a background color and dotted borders to each of them, to make them look concrete.

I will not dig in to the CSS behind the skeleton in this article. But when you add a 3rd column to your blog, you have to tinker with the CSS a bit. Let's see how to do that in the next article.