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 the
link
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
- css/
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.
version="1.6"
into the version of your Joomla! installation.<?xml version="1.0" encoding="utf-8"?> <extension version="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>
<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:<?php defined( '_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="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
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>
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="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" /> <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" /> <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/template.css" type="text/css" /> </head>
Body Section
<body> <jdoc:include type="modules" name="top" /> <jdoc:include type="component" /> <jdoc:include type="modules" name="bottom" /> </body>
Module Positions
Above, the line which saysname="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="<?php echo $this->baseurl; ?>/images/stories/myimage.png" alt="Custom image" class="customImage" />
Custom CSS
You can add custom css like this:<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles.css" type="text/css" />
Full template source code:
<?php defined( '_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="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" > <head> <jdoc:include type="head" /> <link rel="stylesheet" href="<?php echo $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.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 *.*
No comments:
Post a Comment