Joomla Template Tutorial Part 2 - Joomla Template Elements


Part two of my free template tutorial will explain the important template elements required by Joomla, and how they all fit together.

What is a Joomla Template? A quick recap.

A Joomla template is simply a directory located within your Joomla installations "template" directory, which Joomla uses to apply a pre-defined look or theme to your Joomla web site. Template developers create these files, package them all up into a nice little package which allows a Joomla website owner to quickly change the overall look and layout of their website.

So a template isn't simply one file, but a few. A read-to-install Joomla template will most likely be in a compressed file (eg. zip file). Once installed, your template files will be uploaded to your Joomla installation: <joomla installation directory>/templates/YOURTEMPLATENAME/<template files would go here>.

An important thing to note is that there are very few requirements of a Joomla template as far as the code goes. For the sake of simplicity, think of a Joomla template as a pizza. While there are many different types of pizza, your typical pizza has:

  1. Crust
  2. Sauce
  3. Toppings

I could take this much further at the risk of boring you all to death, but I think you get the idea. Just like a pizza, a Joomla template must have a basic composition. The rest is left to the creators imagination.

The Joomla Template Composition

Lets take a quick moment to look at the "must haves" of a Joomla template.

  1. index.php - This is the main template file which defines the Joomla structure.
  2. TemplateDetails.XML - This xml file defines the templates parameters such as template name, type, its author, its included files, etc. Without this file, you cannot install a Joomla template, or get Joomla to recognize your templates existance.

That covers the "must haves". Now lets take that one step further and I will lay out what you "should have". Once again, you can build a template with just two files, but its in your best interest to structure it a bit better and add some additional files as described below.

  1. index.php - Must have
  2. templateDetails.xml - Must have
  3. template_thumbnail.png - This is completely optional, its basically a thumbnail of your template that will be viewable in the Joomla back-end or through the module "template chooser".
  4. Directory named "css" - for the sake of organization
    1. template_css.css - This is where you will keep your template css styles.
  5. Directory named "images" - for the sake of organization
    1. Any images used in your template would go here.

90% of Joomla 1.x templates follow this structure. Most of your 1.5 templates do too, but you should note that in 1.5 the new standard for naming your template's CSS file would be "styles.css".

index.php - The Blueprint

This essential Joomla template file is nothing more than a standard HTML file with some PHP tags inserted in strategic locations. Think of the index.php as the file that tells Joomla where to load certain elements of your Joomla site. It basically says:

  • Load my content here!
  • Load my module positions here!
  • Load my components here!

On the third part of this Joomla template tutorial I will begin digging deeper into the index.php, but for now - just remember that this file structures your Joomla template.

templateDetails.xml - The Coordinator

Without your templateDetails, Joomla just thinks you have uploaded a bunch of miscellaneous files to your server. The templateDetails.xml (notice the uppercase "D") tells Joomla all the information it needs to know about the template. Not so much how the template works, but simply the information related to the template (such as its author, its version, date of creation, and files included with it). Also note that the templateDetails.xml information allows your Joomla template to be installed through the template installer.

Lets take a look at the bare minimums:

<mosinstall type="template" version="1.0.x">
<name></name>
<creationDate></creationDate>
<author></author>
<copyright></copyright>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version></version>
<description></description>
<files>
<filename>index.php</filename>
<filename>template_thumbnail.png</filename>
</files>
<images>
<filename>images/example_image01.jpg</filename>
<filename>images/example_image02.jpg</filename>
</images>
<css><filename>css/template_css.css</filename>
</css>
</mosinstall>

Pretty simple stuff eh? If you were to build a template on your Joomla site (meaning uploading the files to the live or local server in the proper (/templates/YOURTEMPLATENAME/ ) directory, all you would need is the above to get Joomla to recognize your templates existence. Sure, Joomla wouldn't know the name of it, but you could still select this new template in the Joomla administration as your "default" template.

Note that if you do build a template using this very bare minimum templateDetails.xml, you wont be able to package it up and install it elsewhere. When you upload a template package through Joomla's back-end (administration), Joomla checks this file against all the files you have just attempted to upload. So the <files> portion of it must be accurate in order for Joomla to successfully install your template package.

Finally, there are plenty of free programs out there that will AUTOMATICALLY create this file for you. These programs ask you to fill out a simple form then direct it to your template files. Simply Google joomla templateDetails.xml generator.

template_css.css - The Template Stylesheet

While the template_css.css is NOT manditory (or CSS at all for that matter), you will do much better off by including it. If you've read the previous template tutorial, you should understand how important I really think it is.

This file simply defines all of the css styles that are applied to your template design. Things such as:

  • Font colors and sizes
  • Page widths and backgrounds
  • Link colors and behaviors

If you have no clue what CSS is, thats fine, well work on that later. For now - just know that its important, and it is standard practice in Joomla template development to include a /css/template_css.css.

Conclusion

Now that you understand the essential pieces to the puzzle and what they do, we can look further into the process in following Joomla template tutorials. While at first some things may seem complex, its really not too bad! I feel that while there are a good handful of template tutorials out there, many try and force everything down at once - hopefully my approach makes the fundamental elements easier to digest.

Hope it helps!





Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites! title=

Quote this article in website Favoured Print Send to friend Related articles Save this to del.icio.us

Users' Comments (30) RSS feed comment
Posted by Michael, on 12-03-2009 01:09, IP 72.28.80.14, Guest
1. Easy and clear
I am new to Joomla and and to make things worse, I am not a pgogrammer. Regardless, I learned somethigs about how Joomla works. I have been playing with the Index.php and the template html to redifine the columns on my website and I am still looking for some help but I am suspecting it is in the CSS file. 
 
Thank you for taking the time to post this
 
» Reply to this comment...

Posted by ez, on 08-03-2009 18:09, IP 82.22.22.187, Guest
2. Refreshingly structured thought!
Thanks a lot. In short time I have understood so much more at a conceptual level. Your refreshingly structured approach can be an inspiration to the open source community. Perhaps if you are pushed for time (ahem! re: 3 :-) - you could recommend a few links for a structured approach to getting into the actual detail of coding templates and sites.
 
» Reply to this comment...

Posted by jaydip, on 03-03-2009 09:05, IP 59.95.40.180, Guest
3. Good............
thanks for this articles
 
» Reply to this comment...

Posted by hogantime, on 26-02-2009 08:05, IP 68.107.77.161, Guest
4. Thanks
Well done. Thank u!
 
» Reply to this comment...

Posted by greg willson, on 18-02-2009 01:16, IP 219.90.200.25, Guest
5. great work
best I have read so far, thanx.
 
» Reply to this comment...

Posted by Abdiel, on 13-02-2009 23:57, IP 190.76.136.131, Guest
6. Thanks - part3?
Thank you a lot. We're waiting for part3.
 
» Reply to this comment...

Posted by Rasul, on 10-02-2009 14:23, IP 85.147.23.8, Guest
7. Nice Tutorials
Your tutorial is easy to understand. It's good that you start with the basics. Always important even if it's nothing new for me :P Sow I can't wait when you go deeper with your tutorials!! 
 
Keep up the good work!!
 
» Reply to this comment...

Posted by Captain, on 09-02-2009 19:24, IP 196.201.211.75, Guest
8. Great!
Thanks for such a great tutorial. Eagerly awaiting part 3!
 
» Reply to this comment...

Posted by Ajede, on 14-01-2009 02:28, IP 80.167.251.182, Guest
9. Where's Part 3?
Where's Part 3?
 
» Reply to this comment...

Posted by pat, on 12-01-2009 04:35, IP 99.177.90.243, Guest
10. slave
thanks for the effort. I actually looking for one that walks you throught building a simple web site.At least your not talking rocket science yet..
 
» Reply to this comment...

More comments...

Add your comment

 

Latest Joomlaport Stories & News

Free Joomla Templates

Latest Joomla Tutorials

Latest Extension News