Joomla Template Tutorial

Introduction The purpose of this tutorial is to serve as an introduction to creating Joomla! templates. It will cover the essential files and code needed to create a basic template. The code is presented so it can be cut and pasted with very little modification needed. Setting up a directory structure To make the most basic template, create a new folder in the “templates” folder. Name this folder after your template i.e. “mynewtemplate”. Using a text editor (or dedicated editor such as Adobe Dreamweaver) create the files “index.php” and “templateDetails.xml” To keep things organized, make 2 new folders called “images” and “css”. Inside the “css” folder create a file called “style.css”. Although it is fine to place all your CSS code directly in your “index.php” file to start, many web developers prefer to place their CSS code in a separate file that can be linked from multiple pages using the “link” tag. This is the most basic practical setup. Outline of folder and file structure: mynewtemplate/ css/ style.css images/ index.php templateDetails.xml This article is a small, well-defined item that could be completed by someone with a reasonable knowledge of the subject matter and a modest time commitment. If you would like to try writing this article you’re welcome to do so. The subject may be self-evident, but if not then further details should be available on the discussion page. Please add {{inuse}} at the top of this page while editing. For other small, well-defined tasks, please look in the Cookie jar. Thank you. Creating a basic templateDetails.xml file The templateDetails.xml file is essential. Without it, your template won’t be seen by Joomla!. The file holds key “metadata” about the template. Lets look at an example:

mynewtemplate 2008-05-01 John Doe john@example.com http://www.example.com John Doe 2008 GNU/GPL 1.0.2 My New Template index.php templateDetails.xml template_thumbnail.png images/background.png css/style.css breadcrumb left right top user1 user2 user3 user4 footer So, as you can see, we have a set of information between markup tags ( the ). Your best approach is to cut and paste this into your “templateDetails.xml” file and change the relevant bits (such as ). The part should contain all the files that you use – you possibly don’t know what they are called yet – don’t worry update it later. Leave the positions as they are – these are a common set so you will be able to switch easily from the standard templates. Creating a basic index.php file The index.php file becomes the core of every page that Joomla! delivers. Essentially, you make a page (like any html page) but place PHP code where the content of your site should go. Here is the bare-bones code ready for you to cut and paste. Lets start at the top:

The first line stops naughty people looking at your coding and getting up to bad things. The second tells the browser (and webbots) what sort of page it is. The third line says what language the site is in. Now the header for real: The first line gets Joomla to put the correct header information in. This includes the page title, meta information as well as system style sheets and JavaScript. The second creates a link to your style sheet. You will need to change this to the directory name that you chose. Now for the main body: Amazingly, this will suffice! Yes, its a very basic layout, but it will do the job. Everything else will be done by Joomla!. Note: you will need to ensure your menu is set to go into the “top” module position. Finish it off – one last bit: Full template source code:

Packaging the template for installation A directory with several loose files is not a convenient package for distribution. So the final step is to make a package. This is a compressed archive containing the directory structure and all the files. The package can be in ZIP format (with a .zip extension), in TAR-gzip format (with a .tar.gz extension), or in TAR-bz2 format (with a .tar.bz2 extension). If your template is in a directory mytemplate/ then to make the package you can connect to that directory and use commands like: tar cvvzf ../mytemplate.tar.gz * zip -a -r ..mytemplate.zip *.* Note to template developers using Mac OS X systems: the Finder’s “compress” menu item produces a usable ZIP format package, but with one catch. It stores the files in AppleDouble format, adding extra files with names beginning with “._”. Thus it adds a file named “._templateDetails.xml, which Joomla 1.5.x can sometimes misinterpret. The symptom is an error message, “XML Parsing Error at 1:1. Error 4: Empty document”. The workaround is to compress from the command line, and set a shell environment variable “COPYFILE_DISABLE” to “true” before using “compress” or “tar”. See the AppleDouble article for more information. Conclusion You should now have created a template that works. It won’t look like much yet. The best thing to do now is start experimenting with the layout. Retrieved from “http://docs.joomla.org/Tutorial:Creating_a_basic_Joomla%21_template”

~ by jalanrejeki on February 23, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: