Skip to main content

Creating a joomla template

Creating a Simple Template: Step 1

To understand the contents of a template, let’s start by looking at a blank Joomla template.

Template File Components

This section reviews the manual process of setting up template files. Normally, you would install the template using the Joomla installer, which takes care of all these steps.
When constructing your own templates, you need to set up several files and folders in a coordinated manner. A template needs to contain various files and folders. These files must be placed in the /templates/ directory of a Joomla installation, each in a folder designated for that template. If you had two templates installed called Element and Voodoo, your directory would look something like this:
  1. /templates/element  
  2. /templates/voodoo  
Note that the directory name for a template must be the same as the name of the template—in this case, element and voodoo. These names are case-sensitive and shouldn’t contain spaces.
Within the directory of a template, there are two key files:
  1. /element/templateDetails.xml  
  2. /element/index.php  
These filenames and locations must match exactly because this is how they are called by the Joomla core script.The first of these is the template XML file.
This is an XML-format metadata file that tells Joomla what other files are needed when it loads a web page that uses this template. (Note the uppercase D.) It also details the author, copyright, and what files make up the template (including any images used).
The last use of this file is for unpacking and installing a template when using the extension installer in the administrative backend.
The second key file is the primary template file that generates pages, the index.php.
This file is the most important in a Joomla template. It lays out the site and tells the Joomla CMS where to put the different components and modules. It is a combination of PHP and HTML.
Almost all templates use additional files. It is conventional (although not required by the Joomla core) to name and locate them as shown here for a template called Element.
  1. /element/template_thumbnail.png  
  2. /element/params.ini  
  3. /element/css/template.css  
  4. /element/images/logo.png  
These are just examples. Some of the commonly found files in a template are shown below
/element/template_thumbnail.png — A web browser screenshot of the template (usually reduced to around 140 pixels wide by 90 pixels high). After the template has been installed, this functions as a preview image that is visible in the Joomla administration Template Manager.
/element/params.ini –A text file that would store the values of any parameters the template has.
/element/css/template.css — The CSS of the template. The folder location is optional, but you have to specify where it is in the index.php file. You can call it what you want. Usually, the name shown is used, but you will see later that there are advantages to having other CSS files, too.
/element/images/logo.png– Any images that go with the template. Again for organization reasons, most designers put them in an images folder. Here we have an image file called logo.png as an example.

templateDetails.xml

The templateDetails.xml file acts as a manifest, or packing list, that includes a list of all the files or folders that are part of the template. It also includes information such as the author and copyright. Some of these details are shown in the administrative backend in the Template Manager. An example of an XML file is shown here:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.     <!DOCTYPE install PUBLIC "-//Joomla! 1.6//DTD template 1.0//EN"  
  3.     "http://www.joomla.org/xml/dtd/1.6/template-install.dtd">  
  4.     <install version="1.6" type="template">  
  5. <name>960TemplateTutorialStep1</name>  
  6. <creationDate>1/10/10</creationDate>  
  7. <author>Barrie North</author>  
  8. <authorEmail>contact@compassdesigns.net</authorEmail>  
  9. <authorUrl>http://www.compassdesigns.net</authorUrl>  
  10. <copyright>Copyright (C) 2005 - 2010 Barrie North</copyright>  
  11. <license>GPL</license>  
  12. <version>1.6.0</version>  
  13. <description>The first of 4 tutorial templates from  
  14. Joomla 1.6 - A User's Guide</description>  
  15. <files>  
  16. <filename>index.php</filename>  
  17. <filename>templateDetails.xml</filename>  
  18. <filename>params.ini</filename>  
  19. <folder>images</folder>  
  20. <folder>css</folder>  
  21. </files>  
  22. <positions>  
  23. <position>breadcrumbs</position>  
  24. <position>left</position>  
  25. <position>right</position>  
  26. <position>top</position>  
  27. <position>footer</position>  
  28. <position>debug</position>  
  29. </positions>  
  30.   
  31.  <config>  
  32. <fields  name="params">  
  33. <fieldset  name="basic">  
  34. <field  
  35.  name="colorVariation"  
  36. type="list"  
  37. default="white"  
  38. label="Color Variation"  
  39. description="Base Color of template">  
  40. <option  
  41. value="blue">blue</option>  
  42. <option  
  43. value="red">red</option>  
  44. </field>  
  45. </fieldset>  
  46. </fields>  
  47. </config>  
  48. </install>  
Let’s look at what some of these lines mean:
  • <install version="1.6" type="template">—The contents of the XML document are instructions for the backend installer. The option type="template" tells the installer that you are installing a template and that it is for Joomla 1.6.
  • <name>960TemplateTutorialStep1 </name>—This line defines the name of your template. The name you enter here will also be used to create the directory within the templates directory. Therefore, it should not contain any characters that the file system cannot handle, such as spaces. If you’re installing manually, you need to create a directory whose name is identical to the template name.
  • <creationDate>—This is the date the template was created. It is a free-form field and can be anything such as May 2005, 08-June-1978, 01/01/2004, and so on.
  • <author>—This is the name of the author of this template—most likely your name.
  • <copyright>—Any copyright information goes in this element.
  • <authorEmail>—This is the email address at which the author of this template can be reached.
  • <authorUrl>—This is the URL of the author’s website.
  • <version>—This is the version of the template.
  • <files></files>—This is a list of various files used in the template. The files
    used in the template are laid out with <filename> and <folder> tags, like this:
    1. <files>  
    2. <filename>index.php</filename>  
    3. <filename>templateDetails.xml</filename>  
    4. <filename>params.ini</filename>  
    5. <folder>images</folder>  
    6. <folder>css</folder>  
    7. </files>  
    The "files" sections contain all generic files, such as the PHP source for the template or the thumbnail image for the template preview. Each file listed in this section is enclosed by <filename> </filename>tags. You can also include whole folders, such as an image folder, by using the <folder> tag.
  • <positions>—This shows the module positions available in the template. It is the list of page locations, such as top, left, and right, defined in the template in which modules can be set to appear, using the Position drop-down of the Module Manager. The position names in this list must precisely match the PHP code that generates content for each listed position inside index.php.
  • <config>—This section describes the parameters that can be set in the backend and passed as global variables to allow advanced template functions, such as changing the color scheme of the template.

index.php

What is actually in an index.php file? It is a combination of HTML and PHP that determines everything about the layout and presentation of the pages.
Let’s look at a critical part of achieving valid templates: the DOCTYPE at the top of the index.php file. This is the bit of code that goes at the top of every web page. At the top of our page, put this in the template:
  1. <?php  
  2.     /** 
  3. * @copyrightCopyright (C) 2005 - 2010 Barrie North. 
  4. * @licenseGPL 
  5. */  
  6. defined('_JEXEC'or die;  
  7. ?>  
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  9. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
The first PHP statement simply shows the copyright/license and makes sure the file is not accessed directly for security.
A web page DOCTYPE is one of the fundamental components of how a web page is shown by a browser—how various HTML tags are handled and, more importantly, how the browser interprets CSS. The following observation from A List Apart should clarify things:
You can use several DOCTYPEs. Basically, the DOCTYPE tells the browser what version of HTML was used to design the page, whether it has some legacy code or also contains XML, and therefore how to interpret the page.
Here the words strict and transitional start getting floated around (float:left and float:right usually) to indicate whether legacy code was included. Essentially, ever since the Web started, different browsers have had different levels of support for various HTML tags and versions of CSS. For example, Internet Explorer 6 or less won’t understand the min-width command to set a minimum page width. To duplicate an effect so that it displays the same in all browsers, you sometimes have to use browser-specific “hacks” in the CSS that make up for shortcomings in each browser’s adherence to the published standards.
Strict means the HTML will be interpreted exactly as dictated by standards. A transitional DOCTYPE means that the page will be allowed a few agreed upon differences from the standards (for example, continued use of discontinued tags).
To complicate things, there is something called “quirks” mode. If the DOCTYPE is wrong, outdated, or not there, the browser goes into quirks mode. This is an attempt to be backward compatible, so Internet Explorer 6, for example, will render the page as if it were Internet Explorer 4.
Unfortunately, people sometimes end up in quirks mode accidentally. It usually happens in two ways:
  • They use the DOCTYPE declaration straight from the WC3 web page, and the link ends up as DTD/xhtml1-strict.dtd, which is a relative link on the WC3 server. You need the full path, as shown earlier.
  • Microsoft set up Internet Explorer 6 so you could have valid pages but be in quirks mode. This happens when you have an xml declaration put before instead of after the DOCTYPE.
Next is an XML statement (after the DOCTYPE):
  1. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >  
The information I just gave you about Internet Explorer 6 quirks mode is important. In this tutorial, you’re designing only for Internet Explorer 6 and later, and you need to make sure that it’s running in standards mode to minimize the hacks you have to do later on.
Let’s look at the structure of the index.php file header; you want it to be as minimal as possible but still have enough for a production site. The header information you will use is as follows:
  1. <?php  
  2.     /** 
  3. * @copyrightCopyright (C) 2005 - 2010 Barrie North. 
  4. * @licenseGPL 
  5. */  
  6. defined('_JEXEC'or die;  
  7. $app = JFactory::getApplication();  
  8. ?>  
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  10. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  11. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this- 
  12. >language; ?>" lang="<?php echo $this->language; ?>" >  
  13. <head>  
  14. <jdoc:include type="head" />  
  15. <link rel="stylesheet" href="<?php echo $this->baseurl 
  16. ?>/templates/system/css/system.css" type="text/css" />  
  17. <link rel="stylesheet" href="<?php echo $this->baseurl 
  18. ?>/templates/system/css/general.css" type="text/css" />  
  19. <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php 
  20. echo $this->template ?>/css/template.css" type="text/css" />  
  21. </head>  
What does all this mean?
We already discussed the implications of the DOCTYPE statement in the index.php file. The <?php echo $this->language; ?< code pulls the language from the site’s language setting in Global Configuration.
$app = Jfactory::getApplication(); is a variable that allows you to grab various parameters, like the name of the site and use them in the template.The next line is for including more header information: <jdoc:include type="head" />
This code snippet inserts in the generated page (that is, your frontend) all the header information that is set in the Global Configuration. In a default installation, it includes the tags shown here:
  1.  <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  2. <meta  name="robots" content="index, follow" />  
  3. <meta  name="keywords" content="joomla, Joomla" />  
  4. <meta  name="rights" content="" />  
  5. <meta  name="language" content="en-GB" />  
  6. <meta  name="description" content="Joomla! -  
  7. the dynamic portal engine and content management system" />  
  8. <meta  name="generator" content="Joomla! 1.6 -  
  9. Open Source Content Management" />  
  10. <title>Home</title>  
  11. <link href="/Joomla_1.6/index.php?format=feed&amp;type=rss" rel="alternate"  
  12. type="application/rss+xml" title="RSS 2.0" />  
  13. <link href="/Joomla_1.6/index.php?format=feed&amp;type=atom"  
  14. rel="alternate" type="application/atom+xml" title="Atom 1.0" />  
Much of this header information is created on-the–fly, specific to the page (article) that someone is viewing. It includes a number of metatags, and any RSS-feed URLs.
The last lines in the header provide links to CSS files for Joomla-generated pages in general and also in this template:
  1. <link rel="stylesheet" href="<?php echo $this->baseurl 
  2.     ?>/templates/system/css/system.css" type="text/css" />  
  3.     <link rel="stylesheet" href="<?php echo $this->baseurl 
  4.     ?>/templates/system/css/general.css" type="text/css" />  
  5.     <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php 
  6. echo $this->template ?>/css/template.css" type="text/css" />  
The first two files, system.css and general.css, contain some generic Joomla styles. The last one is all the CSS for the template, here called template.css. The PHP code <?php echo $this->template ?> returns the name of the current template. Writing it in this way rather than writing the actual path makes the code more generic. When you create a new template, you can just copy this line (along with the whole header code) and not worry about editing anything.
The template CSS can include any number of files, such as conditional ones for different browsers and for different media, such as print. For example, the following code detects and adds an additional CSS file that targets the quirks of Internet Explorer 6 (we’ll leave it out of our working example here):
  1. <!--[if lte IE 6]>  
  2.     <link href="templates/<?php echo $this->template ?>/css/ieonly.css"  
  3.     rel="stylesheet" type="text/css" />  
  4. <![endif]-->  
The next example is part of a technique for using a template parameter. In this case, a color scheme selected as a parameter in the Template Manager is loading a CSS file that has the same name as the selected color:
  1. <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php 
  2.     echo $this->template ?>/css/<?php echo $this->params- 
  3. >get('colorVariation'); ?>.css" type="text/css" />  
It might generate this:
  1. <link rel="stylesheet" href="/templates/960TemplateTutorialStep1/css/red.css"  
  2. type="text/css" />  

The Joomla! Page Body

Still in the index.php file, now that the <head> part of the page is set up, we can move on to the body tag. Creating your first template will be easy! Ready?
To create the template, all you need to do is use Joomla statements that insert the contents of the main body, plus any modules you want:
  1. <body>  
  2.     <?php echo $app->getCfg('sitename');?><br />  
  3.     <jdoc:include type="modules"  name="top" />  
  4.     <jdoc:include type="modules"  name="left" />  
  5.     <jdoc:include type="modules"  name="breadcrumbs" />  
  6.     <jdoc:include type="component" />  
  7.     <jdoc:include type="modules"  name="right" />  
  8.     <jdoc:include type="modules"  name="footer" />  
  9.     <jdoc:include type="modules"  name="debug" />  
  10. </body>  
The template contains the following, in reasonably logical viewer order:
  • The name of the site
  • The top modules
  • The left modules
  • A breadcrumb bar
  • The main content
  • The right modules
  • The footer modules
  • A debug module
At this point (if you preview it, make sure it’s the default template), the site does not look very awe inspiring.
Tutorial Image
You want to come as close to semantic markup as possible. From a web point of view, this means a page can be read by anyone—a browser, a spider, or a screen reader. Semantic layout is the cornerstone of accessibility.
Notice that you use the first of a number of commands specific to Joomla to create this output:
  1. <body>  
  2.     <?php echo $app->getCfg('sitename');?><br />  
  3.     <jdoc:include type="modules"  name="top" />  
  4.     <jdoc:include type="modules"  name="left" />  
  5.     <jdoc:include type="modules"  name="breadcrumbs" />  
  6.     <jdoc:include type="component" />  
  7.     <jdoc:include type="modules"  name="right" />  
  8.     <jdoc:include type="modules"  name="footer" />  
  9.     <jdoc:include type="modules"  name="debug" />  
  10. </body>  
The PHP echo statement simply outputs a string from the configuration.php file. Here, you use the site name; you could as easily use the following:
  1. The name of this site is <?php echo $mainframe->getCfg('sitename');?><br />  
  2.     The administrator email is <?php echo $mainframe->getCfg('mailfrom');?><br />  
  3.     This template is in the <?php echo $this->template?> directory<br />  
  4. The URL is <?php echo JURI::base();?>  
The jdoc statement inserts various types of HTML output, from either modules or components.
This line inserts the output from a component. What component it is will be determined by the linked menu item: <jdoc:include type="component" />
This line inserts the output for a module location: <jdoc:include type="modules" name="right" />
This line generates content for all modules that have their position set to right. The content generated for those modules is placed in the page in the order set in the Order column of the Module Manager. This is the full syntax:
  1. <jdoc:include type="modules"  name="location" style="option" />  

Using CSS to Create a Tableless Layout: CSS Template Tutorial – Step 2

In this section, you will use pure CSS to make a three-column layout for the Joomla template. You will also be making it a “fixed” layout. There are three main types of web page layouts—fixed, fluid, and jello — and they all refer to how the width of the page is controlled.
  • A fixed layout has the width set to some fixed value.
  • A fluid layout can grow and shrink to the browser window.
  • A jello layout is fluid but between some minimum and maximum values.
A few years ago, fluid width templates were all the rage. Accessibility guys loved them, and it was cool to grab the corner of your browser window and see all that content slide around.
But now, I don’t make fluid templates, but focus on fixed width templates. I firmly believe they are the best fit on today’s Web. Four years ago, many people were still using 800px width screens. The main point of a fluid width was that you could have a web page that looked okay in a 1024px screen, but still could shrink down to the smaller screens still used.
Now, the trend in screens is the opposite. People are getting huge screens; 32% of people browsing Joomlashack.com are doing so with resolutions over 1024px.
With these big screens and a 960px width layout, you get a new problem—readability. Studies have shown that readability onscreen drops off as you go over 960px. So a fluid width will fill that big screen and a) look daft and b) slow down your reading.
A typical design might use tables to lay out the page. Tables are useful as a quick solution in that you just have to set the width of the columns as percentages. However, tables also have several drawbacks. For example, tables have a lot of extra code com-pared to CSS layouts. This leads to longer load times (which surfers don’t like) and poorer performance in search engines. The code can roughly double in size, not just with markup but also with “spacer GIFs,” which are 1×1 transparent images placed in each cell of the table to keep the cells from collapsing. Even big companies sometimes fall into the table trap.

Issues with Table-Based Layouts

  • They are difficult to maintain. To change something, you have to figure out what all the table tags, such as tr and td, are doing. With CSS, there are just a few lines to inspect.
  • The content cannot be source ordered. Many web surfers do not see web pages on a browser. Those viewing with a text browser or screen reader read the page from the top-left corner to the bottom right. This means that they first view everything in the header and left column (for a three-column layout) before they get to the middle column, where the important stuff is located. A CSS layout, on the other hand, allows for “source-ordered” content, which means the content can be rearranged in the code/source. Perhaps your most important site visitor is Google, and it uses a screen reader for all intents and purposes.
When it comes to CSS layouts, there has been a trend toward what have been coined frameworks. The idea is that a consistent set of CSS is used to create the layout, and then that set is maintained for various issues like browser compatibility. For this template we are going to adopt the 960 grid system developed by Nathan Smith. It’s still not very exciting, but let’s look at what the different parts are all about.
With the 960 grid system, you merely have to specify with a class how big you want the grid to be. In this example, I am using a 12-column grid, so for the header to run across the full width of 960px, in the index.php use:
  1. <div id="header" class="container_12"></div> 

Comments

Popular posts from this blog

Learn phpfox

PHPFox  is a social network script, it is an internet application and when you install it, it is a website. The  phpfox  script comes in 3 packages, each with a different set of modules. it has two products: 1. Nebula (upto phpfox 3.8) 2. Neutron (Newer) You can check the demo on :  http://www.phpfox.com =================================================== To clear cache in phpfox follow the following steps, admincp >> Tools >> Maintenance >> Cache Manager >> Click on Clear All button =================================================== To work facebook app on local Following settings need to done in facebook app   1) go => setting => Advance 2) see "OAuth Settings" area and set "Valid OAuth redirect URIs" =  http:// projectdomain /index.php?do=/user/login/, http:// projectdomain .com/index.php?do=/user/register/, http:// projectdomain .com, http:// projectdomain .com/index.php 3) en...

Interview PHP

>> Why do you want to work at our company? Sir, It is a great privilege for anyone to work in a reputed company like yours. When I read about your company I found that my skills are matching your requirements.  Where I can showcase my technical skills to contribute to the company growth. >> What are your strengths? I am very much hard working and optimistic. Hard Working: Work with dedication and determination. Optimistic: work with positive attitude. I am a team player. I am also very hardworking, and will do what it takes to get the job done. >> What are your weaknesses? Gets nervous when talk to strangers I am a bit lazy about which I am not interested I tend to trust people too easily. I am working on it. >> Why should I hire you? With reference to my work experience, I satisfy all the requirement for this job. I am sincere with my work and would never let you down in anyway. I promise you will never regret for the decision to a...

How to Make Your Own PHP Captcha Generator

In this article we will create file based simple yet successful captcha generator. 3 Major Anti-spamming techniques used? Mathematical Operation like Random number + Random Number = -> The user must specify the answer Random word -> User must type the word Random question -> Obvious one which the user should answer correctly [ex: Are you human?] How Captcha works? The captcha generator generates an IMAGE with the question and then put up a session variable storing the value. User input though an input box. Using php POST, we compare the session variable data with the user input and tell whether its a bot or human. Its coding time The Code First let's write the php script which generates the captcha image. We use the simple header-content change technique, from which we can easily bring up an image from a given text. captcha.php PHP Code: array("Num" => "Num"), 1 => array("Are y...