SlideShare a Scribd company logo
1 of 8
Creating a basic Joomla! template
            Unspecified errors have been reported with this page and it requires a technical review.


                    Contents
                      [hide]


1 Introduction

2 Setting up a directory structure

3 Creating a basic templateDetails.xml file

4 Creating a basic index.php file

 o    4.1 Begin

 o    4.2 Head

 o    4.3 Body Section

              4.3.1 Module Positions

 o    4.4 End

 o    4.5 Custom Images

 o    4.6 Custom CSS

5 Testing the template

6 Packaging the template for installation

 o    6.1 Note to Mac OS X users

7 Conclusion

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 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 template.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
thelink tag. This may also shorten the loading time of your pages, since the separate file can be
cached.

This is the most basic practical setup.

Outline of folder and file structure:


     mynewtemplate/
         css/
               template.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.

The syntax of the file is different for each Joomla version.

For           , use the following:
<?xmlversion="1.0"encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN"
"http://www.joomla.org/xml/dtd/1.5/template-install.dtd">
<installversion="1.5"type="template">
        <name>mynewtemplate</name>
        <creationDate>2008-05-01</creationDate>
        <author>John Doe</author>
        <authorEmail>john@example.com</authorEmail>
        <authorUrl>http://www.example.com</authorUrl>
        <copyright>John Doe 2008</copyright>
        <license>GNU/GPL</license>
<version>1.0.2</version>
        <description>My New Template</description>
        <files>
                <filename>index.php</filename>
                <filename>templateDetails.xml</filename>
                <folder>images</folder>
                <folder>css</folder>
        </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>

For             and later, use the following version. Change version="1.6" into the version of your Joomla!
installation.
<?xmlversion="1.0"encoding="utf-8"?>
<extensionversion="1.6"type="template">
        <name>mynewtemplate</name>
        <creationDate>2008-05-01</creationDate>
        <author>John Doe</author>
        <authorEmail>john@example.com</authorEmail>
        <authorUrl>http://www.example.com</authorUrl>
        <copyright>John Doe 2008</copyright>
        <license>GNU/GPL</license>
        <version>1.0.2</version>
        <description>My New Template</description>
        <files>
                <filename>index.php</filename>
                <filename>templateDetails.xml</filename>
                <folder>images</folder>
                <folder>css</folder>
        </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>
</extension>

So, as you can see, we have a set of information between markup tags (the <element>s). Your best
approach is to cut and paste this into your templateDetails.xml file and change the relevant bits
(such as <name> and <author>).

The <files> 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. The <folder> element can be used to define an entire folder at once.

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. The template works
by adding Joomla code into module positions and the component section in your template. Anything
added to the template will appear on all pages unless it is added to one of these sections via the Joomla
CMS (or customised code).

This page will show the bare-bones code ready for you to cut and paste into your own design.

Begin
A Joomla 1.5+ template begins with the following lines:
<?phpdefined('_JEXEC') or die('Restricted access');?>
<!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="<?phpecho$this->language;?>" lang="<?phpecho$this->language;?>"
>

The first line stops naughty people looking at your coding and getting up to bad things.

The second line is the Document Type Declaration (DOCTYPE), which tells the browser (and web
crawlers) which flavor of HTML the page is using. The doctype used above is XHTML 1.0, which is
supported rather well by most modern browsers. You can also decide to use HTML5, a newer version of
HTML that is largely backwards compatible, but contains many new features. To use HTML5, change the
doctype to
<!DOCTYPE html>

You should be aware that this will not work well in Internet Explorer 8 or earlier without a hack. You might
want to investigate this situation and your clients' wishes before deciding on which doctype you want to
use.

The third line begins our HTML document and describes what language the website is in. A html
document is divided into two parts, head and body. The head will contain the information about the
document and the body will contain the website code which controls the layout.

Head
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?phpecho$this-
>baseurl?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?phpecho$this-
>baseurl?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?phpecho$this-
>baseurl?>/templates/<?phpecho$this->template;?>/css/template.css"
type="text/css" />
</head>

The first line gets Joomla to put the correct header information in. This includes the page title, meta
information as well as system JavaScript. The rest creates links to two system style sheets and to your
own style sheet (if it's named template.css and is located in the css folder of your template directory.
So if your temlate is in http://www.mysite.com/templates/my_template/ then the css files will go
in http://www.mysite.com/templates/my_template/css/).

Body Section
<body>
<jdoc:include type="modules" name="top"/>
<jdoc:include type="component"/>
<jdoc:include type="modules" name="bottom"/>
</body>

Amazingly, this will suffice! Yes, it's a very basic layout, but it will do the job. Everything else will be done
by Joomla!. These lines, usually called jdoc statements, tell Joomla to include output from certain parts of
the Joomla system. Note: you will need to ensure your menu is set to go into the "top" module position.
Module Positions
Above, the line which says name="top" adds a module position called top and allows Joomla to place
modules into this section of the template. The type="component" line contains all articles and main
content (actually, the component) and is very important. It goes in the centre of the template.

Note: You can add your own module lines anywhere you want in the body, but you have to add a
corresponding line to the templateDetails.xml file which sits alongside the index.php of your template.

End
Finish it off - one last bit:
</html>

Custom Images
If you want to add any images to the template you can do so like this:
<img src="<?phpecho$this->baseurl;?>/images/stories/myimage.png" alt="Custom
image" class="customImage" />

Here the baseurl variable will fill in the path to your template for you.

Custom CSS
You can add custom css like this:
<link rel="stylesheet" href="<?phpecho$this-
>baseurl?>/templates/<?phpecho$this->template;?>/css/styles.css"
type="text/css" />

Every file which is added must have a line in the templateDetails.xml file for the template.

Full template source code:
<?phpdefined('_JEXEC') or die('Restricted access');?>
<!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="<?phpecho$this->language;?>" lang="<?phpecho$this->language;?>"
>
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?phpecho$this-
>baseurl?>/templates/mynewtemplate/css/template.css" type="text/css" />
</head>
<body>
<jdoc:include type="modules" name="top" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="bottom" />
</body>
</html>

Testing the template
Find the template in the Template Manager, select it and click Default to make it the default template.

       In Joomla! 1.5, your new template will show up immediately in the Template Manager, accessible
via Extensions -> Template Manager.

       + In Joomla 1.6, you first need to tell Joomla! that you have created a new template. This feature is
called Discover Extensions and can be accessed via Extensions -> Extension Manager -> Discover (i.e.
the Discover tab). Click Discover (i.e. the Discover button) to discover your template, then select it and
click Install to install it. Now your template should show up in the Template Manager (Styles), accessible
via Extensions -> Template Manager.

HINT: there are a couple of ways you can preview your index page as you put it together, either insert the
styles into the head of the index page or directly link it to the style sheet you will be using temporarily. You
can remove these links before packaging the file.

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 Mac OS X users
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 theAppleDouble article for
more information.
To set an environment variable on a Mac, open a terminal window and type:


export COPYFILE_DISABLE=true


Then in the same terminal window, change directories into where your template files reside and issue the
zip command. For instance, if your template files have been built in a folder in your personal directory
called myTemplate, then you would do the following:


cd myTemplate
zip -r myTemplate.zip *

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.

Categories: Articles that require a review | Cookie jar | Template Development | Tutorials | Templates

More Related Content

What's hot

Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docs
quyvn
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
Wingston
 
HTML by Telerik Akademy
HTML by Telerik AkademyHTML by Telerik Akademy
HTML by Telerik Akademy
Ognyan Penkov
 

What's hot (20)

Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3
 
Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docs
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
Rapid application development with FOF
Rapid application development with FOFRapid application development with FOF
Rapid application development with FOF
 
HTML 5 Complete Reference
HTML 5 Complete ReferenceHTML 5 Complete Reference
HTML 5 Complete Reference
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3
 
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
Developing a Joomla 3.x Component using RAD/FOF - Joomladay UK 2014
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
 
IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Tags
TagsTags
Tags
 
Introduction to ExtJS
Introduction to ExtJSIntroduction to ExtJS
Introduction to ExtJS
 
HTML by Telerik Akademy
HTML by Telerik AkademyHTML by Telerik Akademy
HTML by Telerik Akademy
 
Polymer
PolymerPolymer
Polymer
 
WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
Wordpress workflow for an agency world
Wordpress workflow for an agency worldWordpress workflow for an agency world
Wordpress workflow for an agency world
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 

Similar to Creating a basic joomla

Designing for magento
Designing for magentoDesigning for magento
Designing for magento
hainutemicute
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
Wingston
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
vathur
 

Similar to Creating a basic joomla (20)

Joomla Templates101
Joomla Templates101Joomla Templates101
Joomla Templates101
 
How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
 
Designing for magento
Designing for magentoDesigning for magento
Designing for magento
 
Creating Custom Templates for Joomla! 2.5
Creating Custom Templates for Joomla! 2.5Creating Custom Templates for Joomla! 2.5
Creating Custom Templates for Joomla! 2.5
 
crtical points for customizing Joomla templates
crtical points for customizing Joomla templatescrtical points for customizing Joomla templates
crtical points for customizing Joomla templates
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
Joomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic TemplatesJoomla! Day UK 2009 Basic Templates
Joomla! Day UK 2009 Basic Templates
 
Joomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic TemplatesJoomla Day UK 2009 Basic Templates
Joomla Day UK 2009 Basic Templates
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
Developing joomla 1.6 templates
Developing joomla 1.6 templatesDeveloping joomla 1.6 templates
Developing joomla 1.6 templates
 
Joomla! Template for Beginners
Joomla! Template for BeginnersJoomla! Template for Beginners
Joomla! Template for Beginners
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practices
 
WebMatrix 100-level presentation
WebMatrix 100-level presentationWebMatrix 100-level presentation
WebMatrix 100-level presentation
 
HTML/CSS Lecture 1
HTML/CSS Lecture 1HTML/CSS Lecture 1
HTML/CSS Lecture 1
 
Web technologies part-2
Web technologies part-2Web technologies part-2
Web technologies part-2
 
HTML (Basic to Advance)
HTML (Basic to Advance)HTML (Basic to Advance)
HTML (Basic to Advance)
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
 
46h interaction 1.lesson Hello world
46h interaction 1.lesson Hello world46h interaction 1.lesson Hello world
46h interaction 1.lesson Hello world
 

Recently uploaded

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Creating a basic joomla

  • 1. Creating a basic Joomla! template Unspecified errors have been reported with this page and it requires a technical review. Contents [hide] 1 Introduction 2 Setting up a directory structure 3 Creating a basic templateDetails.xml file 4 Creating a basic index.php file o 4.1 Begin o 4.2 Head o 4.3 Body Section  4.3.1 Module Positions o 4.4 End o 4.5 Custom Images o 4.6 Custom CSS 5 Testing the template 6 Packaging the template for installation o 6.1 Note to Mac OS X users 7 Conclusion 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 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 template.css.
  • 2. 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 thelink tag. This may also shorten the loading time of your pages, since the separate file can be cached. This is the most basic practical setup. Outline of folder and file structure:  mynewtemplate/  css/  template.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. The syntax of the file is different for each Joomla version. For , use the following: <?xmlversion="1.0"encoding="utf-8"?> <!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.5/template-install.dtd"> <installversion="1.5"type="template"> <name>mynewtemplate</name> <creationDate>2008-05-01</creationDate> <author>John Doe</author> <authorEmail>john@example.com</authorEmail> <authorUrl>http://www.example.com</authorUrl> <copyright>John Doe 2008</copyright> <license>GNU/GPL</license>
  • 3. <version>1.0.2</version> <description>My New Template</description> <files> <filename>index.php</filename> <filename>templateDetails.xml</filename> <folder>images</folder> <folder>css</folder> </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> For and later, use the following version. Change version="1.6" into the version of your Joomla! installation. <?xmlversion="1.0"encoding="utf-8"?> <extensionversion="1.6"type="template"> <name>mynewtemplate</name> <creationDate>2008-05-01</creationDate> <author>John Doe</author> <authorEmail>john@example.com</authorEmail> <authorUrl>http://www.example.com</authorUrl> <copyright>John Doe 2008</copyright> <license>GNU/GPL</license> <version>1.0.2</version> <description>My New Template</description> <files> <filename>index.php</filename> <filename>templateDetails.xml</filename> <folder>images</folder> <folder>css</folder> </files> <positions> <position>breadcrumb</position> <position>left</position> <position>right</position>
  • 4. <position>top</position> <position>user1</position> <position>user2</position> <position>user3</position> <position>user4</position> <position>footer</position> </positions> </extension> So, as you can see, we have a set of information between markup tags (the <element>s). Your best approach is to cut and paste this into your templateDetails.xml file and change the relevant bits (such as <name> and <author>). The <files> 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. The <folder> element can be used to define an entire folder at once. 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. The template works by adding Joomla code into module positions and the component section in your template. Anything added to the template will appear on all pages unless it is added to one of these sections via the Joomla CMS (or customised code). This page will show the bare-bones code ready for you to cut and paste into your own design. Begin A Joomla 1.5+ template begins with the following lines: <?phpdefined('_JEXEC') or die('Restricted access');?> <!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="<?phpecho$this->language;?>" lang="<?phpecho$this->language;?>" > The first line stops naughty people looking at your coding and getting up to bad things. The second line is the Document Type Declaration (DOCTYPE), which tells the browser (and web crawlers) which flavor of HTML the page is using. The doctype used above is XHTML 1.0, which is supported rather well by most modern browsers. You can also decide to use HTML5, a newer version of
  • 5. HTML that is largely backwards compatible, but contains many new features. To use HTML5, change the doctype to <!DOCTYPE html> You should be aware that this will not work well in Internet Explorer 8 or earlier without a hack. You might want to investigate this situation and your clients' wishes before deciding on which doctype you want to use. The third line begins our HTML document and describes what language the website is in. A html document is divided into two parts, head and body. The head will contain the information about the document and the body will contain the website code which controls the layout. Head <head> <jdoc:include type="head" /> <link rel="stylesheet" href="<?phpecho$this- >baseurl?>/templates/system/css/system.css" type="text/css" /> <link rel="stylesheet" href="<?phpecho$this- >baseurl?>/templates/system/css/general.css" type="text/css" /> <link rel="stylesheet" href="<?phpecho$this- >baseurl?>/templates/<?phpecho$this->template;?>/css/template.css" type="text/css" /> </head> The first line gets Joomla to put the correct header information in. This includes the page title, meta information as well as system JavaScript. The rest creates links to two system style sheets and to your own style sheet (if it's named template.css and is located in the css folder of your template directory. So if your temlate is in http://www.mysite.com/templates/my_template/ then the css files will go in http://www.mysite.com/templates/my_template/css/). Body Section <body> <jdoc:include type="modules" name="top"/> <jdoc:include type="component"/> <jdoc:include type="modules" name="bottom"/> </body> Amazingly, this will suffice! Yes, it's a very basic layout, but it will do the job. Everything else will be done by Joomla!. These lines, usually called jdoc statements, tell Joomla to include output from certain parts of the Joomla system. Note: you will need to ensure your menu is set to go into the "top" module position. Module Positions
  • 6. Above, the line which says name="top" adds a module position called top and allows Joomla to place modules into this section of the template. The type="component" line contains all articles and main content (actually, the component) and is very important. It goes in the centre of the template. Note: You can add your own module lines anywhere you want in the body, but you have to add a corresponding line to the templateDetails.xml file which sits alongside the index.php of your template. End Finish it off - one last bit: </html> Custom Images If you want to add any images to the template you can do so like this: <img src="<?phpecho$this->baseurl;?>/images/stories/myimage.png" alt="Custom image" class="customImage" /> Here the baseurl variable will fill in the path to your template for you. Custom CSS You can add custom css like this: <link rel="stylesheet" href="<?phpecho$this- >baseurl?>/templates/<?phpecho$this->template;?>/css/styles.css" type="text/css" /> Every file which is added must have a line in the templateDetails.xml file for the template. Full template source code: <?phpdefined('_JEXEC') or die('Restricted access');?> <!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="<?phpecho$this->language;?>" lang="<?phpecho$this->language;?>" > <head> <jdoc:include type="head" /> <link rel="stylesheet" href="<?phpecho$this- >baseurl?>/templates/mynewtemplate/css/template.css" type="text/css" /> </head> <body> <jdoc:include type="modules" name="top" /> <jdoc:include type="component" /> <jdoc:include type="modules" name="bottom" />
  • 7. </body> </html> Testing the template Find the template in the Template Manager, select it and click Default to make it the default template. In Joomla! 1.5, your new template will show up immediately in the Template Manager, accessible via Extensions -> Template Manager. + In Joomla 1.6, you first need to tell Joomla! that you have created a new template. This feature is called Discover Extensions and can be accessed via Extensions -> Extension Manager -> Discover (i.e. the Discover tab). Click Discover (i.e. the Discover button) to discover your template, then select it and click Install to install it. Now your template should show up in the Template Manager (Styles), accessible via Extensions -> Template Manager. HINT: there are a couple of ways you can preview your index page as you put it together, either insert the styles into the head of the index page or directly link it to the style sheet you will be using temporarily. You can remove these links before packaging the file. 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 Mac OS X users 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 theAppleDouble article for more information.
  • 8. To set an environment variable on a Mac, open a terminal window and type: export COPYFILE_DISABLE=true Then in the same terminal window, change directories into where your template files reside and issue the zip command. For instance, if your template files have been built in a folder in your personal directory called myTemplate, then you would do the following: cd myTemplate zip -r myTemplate.zip * 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. Categories: Articles that require a review | Cookie jar | Template Development | Tutorials | Templates