Your First Joomla Template

How to Create Your First Joomla Template

Tutorial Details
  • Difficulty: Beginner
  • Completion Time: 1-2 hours

In this tutorial , you will learn about the basics of a Joomla template, and create one from scratch. We will quickly go through installing a local server and Joomla itself, and then create a basic functioning template.


1. Preparation

Before we get started on our template, there are a few things you need to prepare.
Just like most CMSs, Joomla requires a server with PHP and MySQL installed. Installing the above manually can be quite annoying and, to be honest, a waste of time (unless you want to get into how it’s done exactly).
What we will be doing is downloading a single installer for all the above that will stick a local server on your system and give you a really nifty control panel too.

So head on over to WAMP and download the latest version.( MAMP for Mac)

Once the installer is downloaded, execute it and install WAMP in a place easy to remember. If all goes to plan you should be looking at a folder named : wamp

You should now also have an icon in your notification bar (where the clock is) that gives you access to WAMP’s control panel. You can use this for a number of things, including restarting the server.


2. Downloading and installing Joomla

Now that we have a server installed, we can get Joomla and set it up. Go to Joomla and download the latest release.

Before we continue, let’s take a look at our wamp folder again. Inside you will find a bunch of folders, but the one we are interested in is the www folder.
This is the root of your server setup and this is where we will be installing Joomla. (note: you can install as many copies of Joomla in here as you want, or anything else for that matter)

So, unpack your Joomla download into the www folder. I usually rename it at this point to the name of my site or just shorten it to joomla.

Joomla is now on our server. However there is one last thing we need to do before installing, and that’s to create a database. Open up your browser and go to http://localhost .
Here you will find the your server admin area, this is where we create our database.

To create the database, click on phpmyadmin under the Your Aliases section.

For this tutorial’s sake we will be calling our database joomla. You will not be creating a user with password here, instead using the root user details. It is strongly recommended that you create a user with a strong password in live situations.

Now that we have a database, we can start installing Joomla. Fire up your browser and go to http://localhost/joomla (or whatever you called your site when unpacking it.)

The first screen pretty much speaks for itself. Choose a language and press next.

The next screen you see is the Pre-Install checklist. This is a list of the required items and settings Joomla needs to successfully install. Make sure you have the necessary configuration and click next.

On the next page, read the license carefully, and, when ready click next and enter the required details(Host Name: localhost , Username: root , no password and joomla as Database name), and press next.

Skip the FTP Configuration screen by clicking next and on the next page, enter your site name, an email address and choose a password. This will be the password you will use to log into the admin area of joomla along with the username: admin.
We will not install any sample data right now, as we want to add the modules one by one to see how our template is coming along later on in the tut. Click next.

Congrats! Joomla is up and running, but before we can go in and mess around we have to delete the installation folder. So go to your www folder inside wamp, and then into the joomla folder and delete the installation folder


3. A closer look at Joomla

It’s pretty hard these days to get into any Open Source CMS discussion without the name of Joomla dropping.
Its installation along with intuitive admin panel makes it very popular with users who are after an easy CMS while, at the same time, being packed with features that keep
thousands of developers busy rolling applications and modules. If necessary, get familiar with the back end ( I recommend this quick Joomla 101 article on the Themeforest blog to get a quick feel.)

To visit your site , click on preview in the upper right corner of the admin area. What you will get is the default template with no content and the most basic of modules loaded.


4. The template

In order to begin understanding the template structure, let’s take a look at the default one. Go to your www folder, then inside the joomla folder you should see a templates folder.
(wamp/www/joomla/templates). This is where all the different templates go. You can switch between templates in the admin panel.

Inside the templates folder, you will see a folder for every template installed. Joomla comes with three templates: beez, rhuk_milkyway and ja_purity. Remember this location as this is where you will be installing your new templates in the future.

Although most templates are made up of quite a few files, only two are needed to make a working template. These are:

  • index.php
  • templateDetails.xml

The first one – index.php – is where all the markup goes in which you stick the Joomla includes. These can be seen as little hooks where joomla hangs up information on, like modules for example

The second file is templateDetails.xml. You can see this as a list of instructions to Joomla. This list must include the name of the template, the names of the files used in the template(images etc..) and the positions you want to use (the includes mentioned above.)

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN"
 "http://dev.joomla.org/xml/1.5/template-install.dtd">
<install version="1.5" type="template">
       <name>template _tut</name>
       <creationDate>31-01-2009</creationDate>
        <author>Nettut Fan</author>
        <authorEmail>your@email.com</authorEmail>
        <authorUrl>http://www.siteurl.com</authorUrl>
        <copyright>You 2009</copyright>
        <license>GNU/GPL</license>
        <version>1.0.0</version>
        <description>Template Tut</description>
        <files>
                <filename>index.php</filename>
                <filename>templateDetails.xml</filename>
                <filename>css/template.css</filename>
         </files>       
                
        
        <positions>
                <position>breadcrumb</position>
                <position>left</position>
                <position>right</position>
                <position>top</position>
               <position>user1</position>
                <position>user2</position>
                <position>user3</position>
                <position>user4</position>
                <position>footer</position>
        </positions>
</install>

The above is an example of a templateDetails.xml file. As you can see, this is a specific list that tells Joomla about the template, like the name, the author, date created etc…
Notice the positions section in the code above. These are the positions we spoke of earlier, the includes.
Some are self explanatory, like footer.
If you put the joomla footer include in the footer area of your design, you will be able to control some aspects of the footer using the Joomla back end. Lets try and throw together a simple template.


5. Beginning the template

Lets do some preparation so we have something to work with. Go to your templates folder , and create a new folder. Lets call it template_tut.

Inside your new folder, create a file called index.php, and another called templateDetails.xml (copy/paste the code in the example above inside it).

Open up your index.php file in notepad or anything else you use to edit code, and copy/paste the following in:

	<!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" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
	<head>
	<jdoc:include type="head" />
	</head>

We have a DOCTYPE, a PHP code for the language, and in the head section our first Joomla include. This is not in the xml list because it is not a position.

		<jdoc:include type="head" />
	

What this does is include the joomla header code (which includes the page title), and a bunch of other stuff that can probably fill half a tutorial on its own.

Finish up the markup on the page by adding the body tags and closing the html tag.


6. Using the template

Now that we have the basic files in place, let’s add another include, this time to display the main content of any given page being viewed.

		<jdoc:include type="component" />

You should now have this in your index.php

	<!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" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
	<head>
	<jdoc:include type="head" />
	</head>

	<body>

	<jdoc:include type="component" />

	</body>
	</html>
    

Before we test our template, let’s add an article so we have some content. Make sure WAMP is running and go to your admin area in Joomla with http://localhost/joomla/administrator

Now enter your login details

Go to Content on the menu and then to Article Manager in the drop down

Click on New to add an article

Give your article a title, fill in an alias, make sure its published to front page and hit save

Let’s see what our article looks like on the front page. Click on preview in the upper right corner after saving. You should see the front page of your site with your text.

Now that we have published content, let’s see if the template we made actually works. Go back to your admin area and click on Extensions and then Template Manager

You should see template_tut in the list, so go ahead and choose it, and set it as default.

Hit preview and check out your glorious new template. Well maybe not so glorious but your first joomla template. YAY!


7. Adding some meat to our template

We got our template working, it’s retrieving the header info including the title and displaying content we created in the joomla back end .Before we add more includes, let’s take a closer look at the module position includes; the ones we named in our xml file.

     
         <positions>
                <position>breadcrumb</position>
                <position>left</position>
                <position>right</position>
                <position>top</position>
               <position>user1</position>
                <position>user2</position>
                <position>user3</position>
                <position>user4</position>
                <position>footer</position>
        </positions>

They are included in the following way:

	<jdoc:include type="modules" name="position_name" />

So in order to add , for example, the left position, our index.php will look like this:

	<!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" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
	<head>
	<jdoc:include type="head" />
	</head>

	<body>

	<jdoc:include type="component" />
	<jdoc:include type="modules" name="left" />
	</body>
	</html>
 

While we are at it, let’s add the footer position

	<!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" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
	<head>
	<jdoc:include type="head" />
	</head>

	<body>

	<jdoc:include type="component" />
    <jdoc:include type="modules" name="left" />
	<jdoc:include type="modules" name="footer" />
	</body>
	</html>
 

If you go back to your admin area, and go to the Module Manager you will notice a module already there, the Main Menu module. This module gets installed even if we choose to install the simple version of Joomla.

The menu is already hooked on to the left position (which we just included in our template), so let’s see what it looks like. Hit preview

As you can see, we now have a menu with a link to Home. You can add more menu items and link to different content through the Menu Manager.

Lets get a footer working. Go to the Module Manager, click new and select Footer. Then press next.

On the following page, give the new module the title: Footer, and in the Position dropdown, select Footer.

Click save and then preview the page.
You should now also see footer information on your template.


8. Adding more positions and modules

Lets style our page a bit so we can see what we are doing. In your template_tut folder create a new folder and call it “CSS” , and create a file inside it called ‘template.css”

Stick the includes in index.php in some divs and wrap it all in a container div and then link your style sheet like the example. Feel free to copy my messy layout if you are not already using one of your own. I did mine real quick for this tutorial.

<!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" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/template_tut/css/template.css" type="text/css" />
</head>

<body>
<div id="container">
	<div id="header"> Header and stuff</div>
	<div id="sidebar_left" class="float"><jdoc:include type="modules" name="left" /></div>
	<div id="content" class="float">
    	<jdoc:include type="component" />
    </div>
    <div id="sidebar_right"class="float">Right sidebar</div>
	<div id="footer" class="clear"><jdoc:include type="modules" name="footer" /></div>
</div>
</body>
</html>

and the CSS


* {
	padding: 0;
	margin:0;
	}
ul {
	list-style:none;
	}
.float {
	float: left;
	}
.clear {
	clear: both;
	}
#container {
	width:960px;
	margin: auto;
	}
#header {
	background-color:#999999;
	height: 150px;
	}
#content {
	width: 660px;
	text-align: center;
	
	}
#sidebar_left {
	text-align: center;
	background-color:#CCCCCC;
	width: 150px;
	}
#sidebar_right {
	background-color:#CCCCCC;
	width: 90px;
	}
#footer {
	background-color:#999999;
	text-align:center;
	}

Lets hook our right sidebar and header up with positions. Add the top position to the header and right position to the right side bar.

<div id="header"><jdoc:include type="modules" name="top" /> </div>

and

<div id="sidebar_right"class="float"><jdoc:include type="modules" name="right" /></div>

Now let’s create the modules for those two positions. Go to the admin area of Joomla, login if necessary, and go to the Module Manager under the Extensions drop down menu. You should see Main Menu and the Footer we created earlier. Follow the same steps to create two more modules. A Search module that you will place in the top position, and a Login module that you will place in the right position.

Preview your page, you should now have a search bar in your header and a login form in your right sidebar. These are pretty much the basics of a Joomla template. You create positions in your design, like little hooks for Joomla to send info to, which in most cases you create in the back end. You can apply this to almost any design using the many positions that Joomla offers. I hope this has been useful to you guys, keep in mind that these are the very basics, Joomla templates can be made as complex and powerful as you want.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Tags: joomla
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.iamonline.in Pro Blogger

    Hi I was wordering if someone can help me with making these module positions collapsible.

    I mean, I create 5 module positions namely box1, box2, box3, box4 and box5.

    All these boxes are in a horizontal line next to each other, in the same row.

    Lets say if I publish modules only in box1, box2 and box3. the other two (box4 and box5 must collapse) and these three published boxes should spread to the entire row’s width.

    In short all unpublished positions must collpse and the published positions must stretch to the row’s width.

  • http://www.srimahigallery.com Madhavi

    Yep I was also wondering how to make these module positions collapse.

  • http://www.codelobster.com Stas

    I suggest to use Codelobster PHP Edition with special Joomla Themplate Editor.

  • http://chickenbit.com bock

    I think you want to use countModules from the joomla API to dynamically determine if the positions should be created:

    http://docs.joomla.org/Counting_modules_in_a_given_module_position

  • Sebastian

    How to convert my css menu to dynamic joomla menus?

  • http://gibson.nl xtian

    This tutorial was what I needed. Start from the most simple template and graduate, step by step, using more and more features. Pity that some essential stuff for newbies (like me) was left out! First of all the includes for the footer and the right position were not included in the example of the index.php script given. The code is shown separately. You have to guess where to put it in the index.php file. I put the include for the right position directly after the include for the left position. When I looked at the page in the front end I found the login module to the left of the text content I had entered – instead of the ‘right’ position. Then I looked at the page with the ?tp=1 added to the url so that I could display the module positions and I saw that the module position for ‘right’ was indeed next to ‘left’, before main content! I then shifted the include code for the right module position further down in the code of my index.php (after the include for the component) and it now works perfectly! YAY.

  • http://www.varsity-ebooks.com raaz

    Try Artisteer 2.0 for very easy joomla template design

  • rex

    Its awesome yaar, great for beginners like me…
    well done dude, keep up ur good work,
    and thanks a lot dude

  • manoj

    i did all things but my template is not present in the template manager

  • Mohit Giri

    It is awesome for beginer like me.i had made my template with the help of this tutorial…mind beloing performance..thnx..dude..

  • surendra

    really very gud plase send me how to customize the site ,how to add topmenu in the customise page not joomla page

  • http://localhost.joomla Maxwell K.

    Great tutorial!!! This article is very helpful for me.
    I expect your further articles.
    Thank you very much.

  • masud rahman

    This tutorial is great.
    This step by step instrucation helped a lot to learn about creating very basic of joomla template.
    A lot simpler than joomla documentation.
    thanks

  • Indika ruwan Senavirathne

    Help is exccelent….

  • gullu Badshah

    very simple and very nice.
    I read one whole book then i got the idea but
    with your tutorial one can learn it in 1 hour
    thank you

  • http://www.lavalleecreative.com Stephen

    Thanks for this…..just found out I need to put together a Joomla template. This comes in quite handy! Any suggestions for more advanced tutorials?

  • http://www.francois-rosenbaum.com Francois

    It’s really the basics.
    What about component.php and the atribute style=”" when adding a new module :
    style=”xhtml”
    should’t it be written this way :
    countModules(‘menu’)) : ?>

    Thanks for your help.
    but it’s not enough for me to build a whole template

  • abhishek

    This is starting good but after the comes the near as there lots of the changes needed that’s also want a help what’s the next step ahead to a good template designer……………

    • silvers

      um… what? haha.

      • shrooms

        hahahaha, didn’t understand a word of it as well..

    • mungkey

      what did you mean by that abhishek?

      anyway good tutorial. cheers

  • wetinwales

    This is the BEST tutorial so far – and I have cried through many.
    So many tutorials are written by people who understand their subject but that does not make them good teachers – necessarily.
    Thanks for this one.

  • gvantsa

    I have problems with this tutorial. In my template manager is an error: XML Parsing Error at 1:74. Error 64: Reserved XML Name. I can’t see my template. I’ve just done everything step by step. I can’t understand what’s going on. What does it mean? Can you help me? Please.

    sorry, my English isn’t as good as it must be.

  • gvantsa

    I’ve reinstalled joomla! and it works! Thanks. Thia tutorial was very helpful for me. :)

  • http://www.ngtech.pk Ahmedij

    Awesome Tutorial for beginners, will post and update soon after creating our first Joomla template :)

  • Paul Wroe

    Great Tutorial! HOWEVER,
    It doesn’t say where to add:

    1.
    2.
    3.and
    4.
    5.

    Any Ideas?

  • http://www.dreamweb.co.in/seo.html seo hyderabad

    very informative tutorial, thanx keep it up

  • Trung

    This was the exact tutorial i was looking for. Taught me exactly what I needed to know. Thank you.

  • http://www.tomcreasey.com Tom Creasey

    I have tried to work with Joomla in the past and have struggled trmendously with it and therefore have resulted to useing WordPress and Drupal (which are also excellent products). This tutorial has broken the ice and I am starting to understand how Joomla works.

    Thanks for this excellent tutorial.

  • http://qontent.blogspot.com qontent

    perfect tutorial….thanks for sharing good treasure..there is something i want to ask if i may to, how to customize the look of i mean the article. because when i try to, they keep showing the table html tag and the look isn’t so nice. thanks

  • Ken412

    Thanks for this excellent introduction.

    Now if any of you are ready to move to the next step, I have recently discovered a series of Joomla tutorials by Compass Designs written by Barrie North here: http://www.compassdesigns.net/joomla-tutorials/

    Section 5 is an excellent description of building a fully featured template from scratch, including full information on CSS styling the design. It even goes as far as describing how to override Joomla’s default output format, so you can convert from its default table based pages to (X)HTML and CSS based pages, as is more appropriate in today’s modern designs.

    But allow yourself plenty of time to read it all, it took me several hours to get to the end and take in all the information!

    Just one small problem, the example code on this page is sometimes not formatted correctly. However, I have found that this whole section of the tutorial has been reproduced (with permission) starting here: http://www.webreference.com/authoring/style/sheets/joomla_templates/index.html . The sample code is correct and the whole tutorial section is broken into multiple pages which you might find easier to digest in smaller chunks.

    Hope this helps anyone looking to move on with their templates. :-)

    • http://qontent.blogspot.com qontent

      yess…this is great..one from compassdesign. i found that really helpfull…thanks for sharing mr. ken

  • http://www.dichvuseo.org Dich Vu Seo

    Awaresome tutourial, you will never got it if you not try to use tutsplus.com
    Thanks for great

  • Mohammad

    I am new to Joomla and confused with template. I wondered no search box and login fields were found. pls reply me.

    • http://zahidbin.blogspot.com Zahid

      In joomla, this things are called modules . there is login module and search module . You need to add modules for login and search box. and then set their positions from the dropdown list.

  • http://zahidbin.blogspot.com zahid

    Nice post . Thanks for writing such a detailed tutorial with images.

  • Nicole

    Hello, I am creating a website in Joomla! using Artisteer. I need to add another header above original one (so it looks like, logo and nav links and below the blog header). I have opened up the css folders on the back door of Joomla! and see template.css, template.ie7.css, template.ie6.css, and editor.css . I decide to click on template.css and edit by copying the header code in the correct spot (or so I think- where my other header code is). When I Save>Apply and preview the website still looks the same as it did before even with the new code. Do I have to go into each template folder? Where should I put the coding? Any other information will help too. Thank you for your time before hand!

  • http://www.webdesigncut.com Webdesigncut

    Hello,
    I have tried to follow this tutorial but after following the initial steps when i added this code to my index.php

    <html xmlns="http://www.w3.org/1999/xhtml&quot; xml:lang="language; ?>” lang=”language; ?>” >

    and tried to preview it shows nothing?

  • KD

    Absolute splendid tutorial: this the most basic and necessary tutorial everybody needs to read!

  • manoj

    very imp for beginner what next step to follow for creating full template

  • Mbone

    This was very helpful. I was able to follow the tutorial with only a beginner’s background on web design. Thanks so much for posting this!

  • http://www.uk.casinomac.eu sebastien

    Thanks for your tuto it was very useful. I understand the basics now. I hope you publish more titorials for Joomla templates.

  • stranger

    Fantastic! I love this, it just the exact thing I’ve been looking for. More power to your elbow.

  • http://www.tezthapa.com.np tez

    gr8 article. Thankx man.

  • Vishal

    Excellent work!
    Thanks

  • Abdulla

    hi,

    I try to access on my admin but it showing me (Error loading Plugins:
    JAuthentication::__construct: Could not load authentication libraries.
    Username and password do not match) but how can change the password, I try to change the password also said user name and email not match, what I have to do, I try to find support from joomla but I did not find their email address.

    could you please help me

    thank you

  • http://nops IndiKid

    Excellent Starter for Joomla and also would prefer more such tutotials for main course!

  • ananthi

    this is the awesome and very useful tutorial for beginners.i read and practice as the way u mentioned and i got nice result .

    thank u so muchhhh

  • http://www.tigrarr.com/ Reny

    Thank you so much! This tutorial is very clear and helpful!

  • http://www.huntlyfc.co.uk Grant Turner

    I can’t get further than the database (step 4)

    and keep getting the following

    “Unable to connect to the database:Could not connect to MySQL”

    I have an SQL databases on my hosts admin setup already but I can’t get joomla to take this info.

    can anyone help?

  • http://sudamsl.wordpress.com sudam

    Nice….!!thanks for the tutorial…..got a lot…

  • Dina

    Thanks .. This was the best Joomla tutorial. It was very helpful.

  • paul

    thanks for the effort, great site, I never heard of this tutplus.com untill now
    I think I’m doing something wrong though, when I try to set the tutorialtemplate as default (so it does show up in template manager) nothing happens, and no star can be seen. What am I doing wrong?
    thanks!

  • http://www.fptservice.com/ adsl fpt

    Very nice tutorial for Joomla but I prefer using WordPress than Joomla, however, thank you for this.

  • Huggs

    HELP please!!! (I’m new with Joomla)
    So I installed the wampserver and Joomla 1.6 (new version) and everything was great so I started to get familiar with Joomla…then I decided to get the old Joomla version since there weren’t too many tutorials out the for the new version (1.6) so I deleted everything and started from scratch but now while im trying to install Joomla I get “Unable to connect to the database:Could not connect to MySQL” in the data base configuration…I tried everything: deleted and reinstall the wamserver and joomla…and still get the same message….please anybody help!!