Making a Real Joomla 1.5 Template
The first thing we need to start with is our comp. A comp is the design that is the basis of the template. We use one kindly donated by Casey Lee, the Lead Designer from Joomlashack14 for our purposes. It's called "Bold," and we can see it in Figure 9.8.
Figure 9.8 A design comp from Joomlashack
Slicing and Dicing
The next step in the process is what is known as slicing. We need to use our graphics program to create small sliced images that can be used in the template. It's important to pay attention to how the elements can resize if needed. (My graphics application of choice is Fireworks, because I find it better suited to web design—as opposed to print—than Photoshop).
Setting Up Module Locations
This template will have some specific locations for specific modules, slightly different from the standard Joomla installation. To make sure the modules are correctly set up as you work through this template, make sure of the following:
- User1=for the search module
- User2=for the top menu
- Top=for newsflash or custom HTML module
Nothing else should be published in these locations.
Header
The header image has a faint swish at the top. We want to retain that, so we put the image in as a background and then assign a color also. That way, the header will scale vertically if we need it to; for example, if the font sizes are resized. We also need to change the colors of any type to white so they show up on the black background.
We also use the background image for the search box. We need to make sure that we target the correct input by using CSS specificity. I have also used absolute positioning inside a relatively positioned element to place the search box where I want it. The image will not scale with text resizing with just a single image. That would require a top and bottom image. That's another exercise for you!
#header { color:#fff; background:#212121 url(../images/header.png) no-repeat; position:relative;} #header h1 { font-family:Arial, Helvetica, sans-serif small-caps; font-variant:small-caps; font-stretch:expanded; padding-left:20px;} #header input { background:url(../images/search.png) no-repeat; border:0; height:22px; width:168px; padding:2px; font:1em Arial, Helvetica, sans-serif; } #header .search { position:absolute; top:20px; right:20px; }
I did not use a graphical logo here; I used plain text. The reason is mainly because SEOs, as search engines, cannot read images. One could do some nifty image replacement, but I will leave that as an exercise for you to do on your own.
Our header now looks like what's shown in Figure 9.9.
Figure 9.9 Header image background
Next, we need to implement a technique used to show a background on a fluid column: sliding doors.
Column Backgrounds
Recall that when we put a color background on the columns, the color did not extend all the way to the footer. This is because the div element, in this case sidebar and sidebar-2, is only as tall as the content. It does not grow to fill the containing element.
We have to use a technique called Sliding Faux Columns, with which you essentially create two wide images that will slide over each other. We need to create two new containers to hold the backgrounds. Normally, we could apply one to the #wrap, but I am using an extra (and wasteful) container for illustration purposes.
For a full description, you can check out these two guides:
- http://alistapart.com/articles/fauxcolumns/
- www.communitymx.com/content/article.cfm?page=1&cid=AFC58
In our case, our maximum width is 960px, so we start with an image of that width. In the image source files, it is slidingcolumns.png. We then export two slices (I used the same slice and just hid/revealed the side images), one 960px wide with a 192px background on the left, and one 960px wide with a 196px background on the left.
Where does 192px come from? It's 20% of 960, as our columns are 20% wide.
We use the background-position property to place the images in the correct place. Here, we are using condensed CSS format so they are part of the background property:
#leftfauxcol { background:url(../images/leftslidingcolumn.png) 20% 0; } #rightfauxcol { background:url(../images/rightslidingcolumn.png) 80% 0; }
In our index.php, we simply added an inner container inside the wrap:
<div id="wrap"> <?php if($this->countModules('left')) : ?> <div id="leftfauxcol"> <?php endif; ?> <?php if($this->countModules('right')) : ?> <div id="rightfauxcol"> <?php endif; ?> <div id="header">
We also need to put a conditional on the closing divs:
<?php if($this->countModules('left')) : ?> </div> <!--end of leftfauxcol--> <?php endif; ?> <?php if($this->countModules('right')) : ?> </div> <!--end of rightfauxcol--> <?php endif; ?>
We must also put a background on our footer and bottom modules/elements; otherwise, the column background would be shown:
#footer { background:#212121; color:#fff; text-align:right; clear:both; } #bottom { background:#333; color:#666; padding:10px 50px; }
We need to clear the floats so that the float container (the faux columns) will extend to the bottom of the page. The traditional method to do this was to use the property :after.15 But with the release of IE7, this method will not work completely. We need to address clearing the floats in Internet Explorer 6 and 7, and this is where it all goes down the tubes.
A couple16 of solutions have been found17; we are going to use the Float (nearly) Everything option18 here.
Thus, we add a simple clear:both to the #footer, and we add floats to the fauxcol wrappers. We add these to a conditional stylesheet specifically for IE6:
#leftfauxcol { float:left; width:100%; } #rightfauxcol { float:left; width:100%; } #footer { float:left; width:100%; }
We will have to add some conditional statements to the head of the index.php file:
<!--[if lte IE 6]> <link href="templates/<?php echo $this->template ?>/css/ie6only.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if lte IE 7]> <link href="templates/<?php echo $this->template ?>/css/ie7only.css" rel="stylesheet" type="text/css" /> <![endif]-->
Flexible Modules
In our design, we have a large initial module block. We don't know how tall the text will be that is needed. To solve that problem, we put the module jdoc:include statement in a containing element and give it a background of the same color as the image. This is the same strategy we used for the header:
<?php if($this->countModules('top')) : ?> <div id="top"> <div class="inside"> <jdoc:include type="modules" name="top" style="xhtml" /> </div> </div> <?php else : ?> <div id="top"> </div> <?php endif; ?>
Note, we have also used a conditional comment so that if the top module location has no content, the orange teaser image will not be there. What will be there is an empty container that will contain a little of the background image and 20px worth of vertical padding. This is purely for aesthetics.
The CSS needs to use CSS specificity to override the moduletable styles defined earlier:
#top { background:#ea6800 url(../images/teaser.png) no-repeat; padding:10px; } #top .moduletable h3 { color:#fff; background:none; text-align:left; font:2.5em Arial, Helvetica, sans-serif normal; padding:0; margin:0; font-stretch:expanded } #top .moduletable{ font:bold 1em/1.2 Tahoma,Arial, Helvetica, sans-serif; color:#fff; margin:0; padding:0; border:0; }
Now we need to focus on some of the typography.
Typography
Many of the links will need to be white, so we will define them as such globally and then modify the color for the center column:
a:link,a:visited { text-decoration:underline; color:#fff; } a:hover { text-decoration:none; } #content60 a:link,#content60 a:visited,#content80 a:link,#content80 a:visited,#content100 a:link,#content100 a:visited { color:#000; }
The design has a stylize button. We create this using a background image from the comp. It's a thin slice that is tiled horizontally:
.button { border:#000 solid 1px; background:#fff url(../images/buttonbackground.png) repeat-x; height:25px; margin:4px 0; padding:0 4px; cursor:hand; }
For tables, such as FAQ, we can add an easy background by repeating the use of the image we used for the teaser. Reusing the image is thematic and also saves on image download, making the pages load faster.
.sectiontableheader { background:url(../images/teaser.png); padding:5px; color:#fff; font:1.2em bold Arial, Helvetica, sans-serif; }
Modules need just a simple redefinition and adjustments to the padding and margins:
/* Module styling */ .moduletable { margin-bottom:1em; color:#fff; font-size:1.1em; } .moduletable h3 { font:1.3em Tahoma,Arial,Helvetica,sans-serif; background:#000; color:#ccc; text-align:left; margin:0 -10px; padding:5px 10px; }
Menus, as always, need a lot of CSS style. Here, we keep it as simple as possible. We slice a single image that includes both the bullet and the underline, not that the styling is turned "on" by applying a module suffix of menu to any list of the links that we want this look applied to:
/*Menu Styling*/ .moduletablemenu { margin-bottom:1em; } .moduletablemenu h3 { font:1.3em Tahoma,Arial,Helvetica,sans-serif; background:#000; color:#ccc; text-align:left; margin:0 -10px; padding:5px 10px; } .moduletablemenu ul { list-style:none; margin:5px 0; } .moduletablemenu li { background:url(../images/leftmenu.png) bottom left no-repeat; height:24px; font:14px Tahoma,Arial, Helvetica, sans-serif; margin:10px 0; padding:0 0 0 10px; } .moduletablemenu a:link,.moduletablemenu a:visited { color:#fff; display:block; text-decoration:none; padding-left:5px; } .moduletablemenu a:hover { text-decoration:none; color:#fff; background:#ADADAD; }
Last is the Tab menu at the top right. As an accessibility advocate, we want to set this up so that the tabs will scale as the font is resizing. Fortunately, a technique has been developed to do this; it's actually the same principle we use for our columns, the sliding doors19 again!
We will also try and do some speed optimization for the template and use just a single image for the left and right side of the "doors," as well as the on and off state. This is known as using sprites.20
The CSS is not too hard; we just have to fiddle around with the vertical position of the image background for the "on" state:
/*Tab Menu Styling*/ .moduletabletabs { font:bold 1em Georgia, Verdana, Geneva, Arial, Helvetica, sans-serif; } .moduletabletabs ul { list-style:none; float:right; margin:0; padding:0; background:#212121; width:100%; } .moduletabletabs li { float:right; background:url(../images/tabs.png) no-repeat 0 -4px; margin:0; padding:0 0 0 12px; } .moduletabletabs a:link,.moduletabletabs a:visited { float:left; display:block; color:#000; background:url(../images/tabs.png) no-repeat 100% -4px; text-decoration:none; margin:0; padding:7px 18px 5px 9px; } .moduletabletabs #current { background:url(../images/tabs.png) no-repeat 0 -84px; } .moduletabletabs #current a { color:#fff; background:url(../images/tabs.png) no-repeat 100% -84px; }
We also need to add the module suffix of tabs to the module for the menu we are using.
If you look back at the original design, you notice that there were icons on these tabs. As we are already using two background images, one on the li and one on the link, we would need a third element on which to place the icon background. You could do this by having a span, but this is advanced CSS Jujutsu. I'll leave that as a homework assignment.
The last thing that remains is to revise the templateDetails.xml file. It needs to contain all the files and images used in the template so it will install properly as a zip file. There are a number of tools that will do this automatically for you if you are using 1.0.X, but at the time of writing, none are available for 1.5.
Our finished template should look like Figure 9.10.
Figure 9.10 Advanced template with typography
CSSTemplateTutorialStep3
We now have a template based on a comp (or design). Some simple typography has been added, but more importantly, we have created a pure CSS layout that has dynamic collapsible columns and a slick tabbed menu. I have created an installable template that is available from www.joomlabook.com: CSSTemplateTutorialStep3.zip.
Now that we have the basics done, let's start delving into some of the advanced features possible with 1.5 templates.