News Feed E-mail

Get How-To's right in your inbox. Subscribe to the HowToJoomla! news feed e-mail. Just enter your email address here:

Delivered by FeedBurner

Login






Lost Password?
No account yet? Register

Affiliates

Azrul's JomComment
JoomlaShack
iJoomla
The Joomla! Store
Member of W3C Sites dot com
How to Create a Basic Template PDF Print E-mail
Written by Cory   
Monday, 25 September 2006
Article Index
How to Create a Basic Template
Step 1: Design
Step 2: HTML Markup
Step 3: CSS
Step 4: Joomlafy
Steps 5-9
Sample Template Files

Step 4: Joomlafy

The next step is to "Joomlafy" our 'index.php' and 'template_css.css' files. Here is the XHTML markup, Joomlafied:

XHTML Markup

 
<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
// needed to seperate the ISO number from the language file constant _ISO
$iso = explode( '=', _ISO );
// xml prolog
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php mosShowHead(); ?>
<?php
if ( $my->id ) {
  initEditor();
}
?>
<meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
<link href="<?php echo $mosConfig_live_site; ?>/templates/redspheres/css/template_css.css" rel="stylesheet" type="text/css" />
 
</head>
 
<body id="bodybg">
 
<div id="sidebar">
 
  <h1 id="sitetitle"><a href="index.php"><?php echo $mosConfig_sitename; ?></a></h1>
  <h2 id="siteslogan">Your source for red spheres</h2>
 
<?php
  if( mosCountModules( 'left' ) > 0 ) {
    mosLoadModules( 'left', -2 );
  }
?>
 
</div><!-- end sidebar -->
 
<div id="mainbar">
 
  <?php mosMainBody(); ?>
 
</div><!-- end mainbar -->
 
</body>
</html>

Now that we have our "Joomlafied" XHTML markup, let's take a look at what's different. In the header, I have added the following code:

 
<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
// needed to seperate the ISO number from the language file constant _ISO
$iso = explode( '=', _ISO );
// xml prolog
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php mosShowHead(); ?>
<?php
if ( $my->id ) {
  initEditor();
}
?>
<meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
<link href="<?php echo $mosConfig_live_site; ?>/templates/redspheres/css/template_css.css" rel="stylesheet" type="text/css" />
 
</head>
"defined( '_VALID_MOS' )..."

The first line, "defined( '_VALID_MOS')...", prevents direct access to the 'index.php' file.

mosShowHead

Another important part to note is the line that says "mosShowHead". I have used this in place of my "title" and "meta" tags because Joomla! uses this function to automatically show the site's title along with important meta tags.

initEditor

The third part I would like to point out is "initEditor". This function initializes the WYSIWYG editor for the front end of your site. It is inside a conditional statement that tests whether or not the user is logged in. The conditional statement improves load time for users who are not logged in, because it prevents Joomla! from executing the initEditor function when it is not necessary.

echo $mosConfig_live_site

You should also note that the link element has been changed to use an absolute href for the template's CSS file. Using $mosConfig_live_site along with the path to the template (templates/redspheres...), your template now knows exactly where its corresponding CSS file is.

Now let's take a look at what else we've added to "Joomlafy" our 'index.php' file.

Left Module Position

The following code is used to 1) determine whether or not there are modules published to the "left" module position, and 2) load those modules in the "left" module position with a style of -2. (see "mosLoadModules - An Explanation")

 
<?php
  if( mosCountModules( 'left' ) > 0 ) {
    mosLoadModules( 'left', -2 );
  }
?>
Main Body

The following code is used to load the Main Body of your Joomla! template. This is where all content items and components are loaded for your Joomla! site.

 
  <?php mosMainBody(); ?>

CSS Code

 
* {
  margin: 0;
  padding: 0;
}
 
body {
  background-color: #fff;
  color: #666;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
}
 
a, a:link, a:visited {
  color: #900;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  color: #000;
}
 
h1#sitetitle {
  padding: 100px 0 0;
  background: #fff url(../images/logo.png) center top no-repeat;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  color: #000;
}
h1#sitetitle a, h1#sitetitle a:link, h1#sitetitle a:visited {
  text-decoration: none;
  color: #000;
}
h1#sitetitle a:hover {
  text-decoration: none;
  color: #000;
}
h2#siteslogan {
  font-size: 14px;
  font-weight: bold;
  margin: 0 0 10px;
  text-align: center;
  color: #000;
}
 
#sidebar {
  width: 215px;
  margin: 10px 0 10px 10px; 
  float: left;
  color: #000;
}
 
#mainbar {
  margin: 10px 10px 10px 235px;
}
 
/* Joomla Elements */
 
/* Moduletable DIV's */
#sidebar .moduletable {
  margin: 10px 0;
}
#sidebar .moduletable h3 {
  border-bottom: 1px solid #ccc;
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 10px;
  padding: 0 0 0 5px;
}
 
/* Main Menu */
ul {
  padding: 0 0 0 5px;
}
li {
  list-style-type: none;
  padding: 3px 0 3px 18px;
  background: #fff url(../images/bullet.gif) 0 5px no-repeat;
}
ul#mainlevel a, ul#mainlevel a:link, ul#mainlevel a:visited {
  text-decoration: none;
  color: #900;
}
ul#mainlevel a:hover {
  text-decoration: underline;
  color: #000;
}
 
/* Login Form */
#mod_login_username {
  width: 205px;
  margin: 0 5px 5px;
  border: 1px solid #ccc;
}
#mod_login_password {
  width: 205px;
  margin: 0 5px 5px;
  border: 1px solid #ccc;
}
#mod_login_remember {
  margin: 0 0 0 5px;
}
input.button {
  border: 1px solid #ccc;
  background-color: #eee;
  color: #666;
  padding: 3px;
  margin: 5px;
  font-size: 10px;
}
label {
  margin: 0 0 0 5px;
}
 
/* Search Form */
#mod_search_searchword {
  width: 205px;
  margin: 0 5px 5px;
  border: 1px solid #ccc;
}
 
/* Main Content Area */
.componentheading {
  display: block;
  font-size: 20px;
  color: #666;
  font-weight: bold;
  border-bottom: 1px solid #ccc;
  margin: 0 0 10px;
}
 
.contentheading {
  font-size: 20px;
  color: #900;
  font-weight: bold;
  margin: 0 0 2px;
}
 
.small, .createdate, .modifydate {
  font-size: 10px; 
  font-weight: normal;
}
 
a.readon {
  display: block;
  padding: 3px 0 3px 18px;
  background: #fff url(../images/bullet.gif) left center no-repeat;
  margin: 5px 0 0;
}
 
.article_seperator {
  display: block;
  height: 10px;
}

We also Joomlafied our CSS code. Everything below "Joomla Elements" was added to the CSS for Joomla!-specific elements. I will not take time to discuss the Joomla!-specific CSS elements, but rather I will just give you a link to "A Blank Template CSS file for Joomla" from CompassDesign.



 
Tag it:
Delicious
Digg
Technorati
< Prev   Next >
Advertisement

About HowToJoomla

HowToJoomla was started in September 2006 by me, Cory Webb, a long-time Mambo/Joomla user with a desire to give back to the community that has given so much to him.

HowToJoomla is not the best, most comprehensive Joomla tips site out there. That's not the goal. The goal is to share some of the knowledge and experience that I have gained through years of using the world's best content managment system. I hope that you will find this site useful and visit often. As I come across new tips and ideas, I will post them here for all to see.

I hope you enjoy using HowToJoomla and find it very useful.

Please take some time to read the Disclaimer.

Thanks for visiting!

About Me

I am a 29-year-old husband and father of a beautiful baby girl named Lucy. I have a degree in Electrical Engineering from the University of Texas at Austin, an MBA from Baylor University, and over 4 years experience working with the Mambo/Joomla CMS.

On February 1, 2008, I started a web design, development, and consulting company specializing in designing and developing custom Joomla-powered websites. The new company is aptly named Cory Webb Media, LLC. The double meaning is purely unintentional, but with a last name like "Webb" it is difficult to escape the obvious puns. If you are looking for professional assistance with your website, please feel free to contact me to discuss your project.

I also run HowToJoomla, CoryWebb.com (my personal website/blog), and JoomlaForm.com (a site dedicated to promoting good design in the Joomla! community). In my spare time (if there is such a thing), I volunteer with the youth ministry at my church.

Copyright © 2006 - Cory Webb Media, LLC - All rights reserved.
Powered by Joomla! | Hosted by Eleven2
The Joomla!® name is used under a limited license from Open Source Matters the worldwide trademark holder.