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
Add Comment

Discussion 393 Comments

Comment Page 8 of 8 1 ... 6 7 8
  1. George says:

    really great tuts.

    i am using joomla 1.6 and i created a new template in the template folder of joomla instalation. but i couldn’t see it in the template manager. any assistance please?

    • loo says:

      George
      April 13, 2011 at 4:47 am

      really great tuts.

      i am using joomla 1.6 and i created a new template in the template folder of joomla instalation. but i couldn’t see it in the template manager. any assistance please?

      I HAVE THE SAME PROBLEM!!! CAN ANYONE SOLVE IT???

  2. Gustavo says:

    Very Simple, but very nice!

  3. Arun says:

    Really Superb!!!!!!!!!!!!!!….. very very thanks………….

  4. sami says:

    I like the theme, thanks very much

  5. sandy says:

    i tried this one but i get these errors please give me the solution.

    Notice: Trying to get property of non-object in C:\wamp\www\Joomla_1.6.3-Stable-Full_Package\libraries\joomla\installer\adapters\template.php on line 44

    Fatal error: Call to a member function attributes() on a non-object in C:\wamp\www\Joomla_1.6.3-Stable-Full_Package\libraries\joomla\installer\adapters\template.php on line 45

  6. alex traut says:

    It really helped me a lot. thanks .

  7. Patricia says:

    Thank you very much for this tutorial. I’m very new to Joomla (having only created a couple of Joomla 1.5 sites) so your breaking this down and explaining it helped me quite a bit. Thank you!

    • Charles says:

      Nice site you have……….

      Hi, I want to start using Joomla for my site which I have built already. I saw your post that you are using your own template also, can you tell me how you added your codes and paragraphs inside the body?

      I dont know how to include them to create it as a module.

      Or you think I should just install normal and then edit it myself from the template editor ?

      Thanks in advance.

      Charles

  8. veronica says:

    Really great tutorial!… I finally found how to make my own templates in joomla… I’m new at this and I’ve been trying to learn how joomla works. This tutorial help me a lot. Thanks…

    I also have a question. I’m working with joomla 1.6 and using my template, I created an article and I inserted a Read More link. But, when I click the link, it doesn’t work (it doesn’t show the rest of the text). I read that I need an html folder inside my template folder. I used another template (any of the ones that comes with joomla) and the link really worked… but I haven’t found what is what I really need, in order to make my own template work with this link. I tried copying the html folder from one of the templates that comes with joomla, but it didn’t work :( … I really appreciate if there is anyone who can help me solve my question.

    • Veronica says:

      Ok… never mind… I finally found my error, after looking a lot of tutorial of how to make a template. It was just that I was missing a very important line of code: … Sorry about that.

      It’s still a great tutorial!

      • Himadri says:

        Which Line of Code you missed? It will be great if you can share it here…Thanks in advance..:-)

  9. Nurul Amin says:

    Nice tuts. I love it.

  10. Stu says:

    Nice one, I’ve started using this as a basis when I’m designing a template rather than hacking an existing template.

  11. Akin says:

    Hi – nice tutorial attempt but there are some problems. Not sure if this was the intention but a novice couldn’t follow your instructions to the letter and arrive at a complete Joomla template – even a simple one.

    It has great detail at the beginning but it seems like you got bored with it at the end. The last two lines of code, where do they go in the index.php? It would have been useful to see a complete index.php so readers can compare notes and at least have an idea that they have followed your instructions correctly.

    If you till have your test installation you did this in – why not paste the last bit in? Otherwise a useful guide.

    Thanks

    Akin

  12. Harsimran Singh says:

    Chak te fatte…..
    really amazing….
    thanx a lot……..

  13. deven says:

    Great Tut , very easy to learn … thanks..

  14. Arun Gopal says:

    Hi very simple!!!! Thanks

  15. ed says:

    Great tutorial! Very useful.

    Thanks!

  16. hardik says:

    i want to create a shopping website from scratch. i have made it in php only. now i want it to do it with joomla. so need tutorial how to build from starting.

  17. agrant says:

    I recently downloaded Joomla 1.7 and created the custom template as instructed, but there’s a problem.
    After I activated the extension lookup for my custom template, then looked in the template section of Joomla to see no assets of that template. Is it possible that there is a syntax error due to the files versions? Even after checking for that error I can selected the file. Here’s the markup:

    Template Details:

    template _tut
    31-01-2009
    Some Dude
    your@email.com
    http://www.siteurl.com
    You 2009
    GNU/GPL
    1.7.0
    Template Tut

    index.php
    templateDetails.xml
    css/template.css

    breadcrumb
    left
    right
    top
    user1
    user2
    user3
    user4
    footer

    Thank you in advance.

    • agrant says:

      Oops…I reviewed the syntax and realized that there was an error. The extension tag wasn’t closed of which prevented it from showing up in the Template Manager. So far Joomla is pretty fun so far and I recommend it to anyone interested in CMS. The trick is to keep up with the updates.

  18. Aravind says:

    Hi,

    First, Thank you very much. I thought it very difficult o create a template. But u made me to feel it easy.. But still I need help I need to know how to create component position. Please help me in this..

    Great Tutorial…

  19. agus says:

    nice tutorials.. thanks it helps me..

  20. vanita says:

    Hello,
    but this code is not woking in Joomla 1.7. Would you please tell me, how to create new tempelte in new joomla version. please reply me asap.

    Thanks
    Vanita

  21. Marcos says:

    Hello, If somebody can help me,

    I have this problem, at the time to select the template_tut this will happen :

    JFolder: :files: Path is not a folder. Path: C:\wamp\www\askjerry\templates\template_tut\css

    somebody has an idea?

    thank you so much

  22. What a great tutorial… Thanks a lot for this.

    I have one question: How can I make the templates I create have menu assignment parameter in the template manager?

  23. Gab says:

    Thanks soo much
    Im new very new and learning how to create site in joomla
    thx soo much, its difficul to understand for me, but i try lots
    thx
    nice and blessed day
    Gab

  24. warda says:

    this an inserting website keep it up OK?

  25. warda says:

    Thanks soo much
    Im new very new and learning how to create site in joomla
    thx soo much, its difficul to understand for me, but i try lots
    thx
    nice and blessed day
    warda

  26. owais says:

    hi.. thanks for all this stuff. very useful information. but i have a query can anyone tell me i have created a template and i hooked some articles to the menu but i want to put them in blog layout of two coloumn. but when i am configuring that in article -> options-> blog/layout its not coming in two coloumn layout.. please can anyone help me out by this…

  27. maaz says:

    this is very usefull to me ….
    it is easy to learn for beginners…………..
    thanks

    and

    i want the sample text for .php file

  28. Eric says:

    Thank you. Very clear and useful. Do you plan to write some more of that kind ? (would be great…)

  29. Paolo says:

    Finally a tutorial that doesn’t just say “copy and paste this…” but actually explains what is going on!

  30. Stan says:

    This is the best tutorial on creating your own joomla templates. Thanks a lot.
    I do have one little promblem, after discovering the template_tut using extension manager discover feature i still cant make the template_tut the default template.
    Anyone knows how to do this please tell me. Thanks in advance

  31. smai says:

    great collection themes.. thanks for share it

  32. ajiths says:

    Nice tutorial………………Plz provide “How to develop modules “………….

  33. Tania says:

    To who is having trouble making the template default, after discovering, make sure that what’s in your templateDetails.xml between <name> </name> is exacly the same as the name of your template folder. For ex. if your template is in the folder MyTemplate , it should be <name> MyTemplate </name>

    Hope it helps

    PS: sorry about the previous 2 comments.. forgot the < and &gt thingy and got confused…. bad english

  34. sedrd says:

    very easy to learn … thanks.

  35. Steve says:

    I would not use WAMP or MAMP. I’d use AMPPS. It autoinstalls on mac and pc as well as IIS servers with one click. Softaculous is installed automatically. It’s years ahead of anything else. Saved my company a weeks worth of time.

  36. Bob R says:

    This is the best Joomla template tutorial that I have seen online. I had the basic one running in about 15 minutes. Thanks for taking the time to create this!

  37. manoz says:

    great post….

  38. clare says:

    I really like CMS, very interesting

  39. Jude says:

    This is really techy! Anyway, thanks for the information.

  40. Alexa says:

    Completely new to php and Joomla. I’m a little bit ticked that you didn’t add a screen shot of what this should have looked like at the end. Other than that… awesome article.

  41. Christian Jorgensen says:

    Thank you. In this very simple and down to earth tutorial you gave me, a novice to joomla templates, everything I need to progress in my own pace and no advanced concepts that would only confuse me at this stage.

  42. Mehrdad says:

    thanks . very good !

  43. Arif says:

    Superb Its very easy to understand. thanks for sharing :)

  44. mangesh says:

    It really helped me a lot. thanks ssssss

  45. Nayon says:

    Really Helpful Tutorial ……………. Thanks.

  46. rockwelcome says:

    how to add new template(make by me) in joomla 1.7 …
    step by step..what means of xml in joomla?

  47. bhavisha says:

    First i say tnx its geate Tut.
    i have no any idea about joomla or templ. but its very easy to learn

    agin i will say tnx

  48. Naveen says:

    Really Superb. Simple and easy to do.. Till now i was customizing the existing template to meet the design provided but now on i can start create my own template according to the design from the scratch…

    Thanks a lotttttttttt….

  49. SUREN says:

    how to add a template in joomla.

  50. Honestly speaking,I am afraid that is it possible for me to create a Joomla template.
    But you nicely describe that now i think it s very easy to create a simple joomla template

    9999999999999999 Thanks.

Comment Page 7 of 7 1 ... 5 6 7

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.