| Joomla Template Tutorial - The Template Components |
|
Page 5 of 12
The Template ComponentsIn order to understand the contents of a template, we will start by looking at a blank joomla template. Important Update The PDF version and template files are in a new location in our Joomla 1.5 powered library. In this template are the various files and folders that make up a Joomla template. These files must be placed in the /templates directory of a Joomla installation. So, if we had two templates installed, our directory would look something like:/templates
/JS_Smoothportal /JS_Synergy Note that the directory names for the templates must be the same as the name of the template, in this case JS_Smoothportal and JS_Synergy. Obviously they are case sensitive and shouldn't contain spaces. Traditionally the designers initials or name is used as a prefix. Within the directory of a template, there are a number of key files: /JS_Smoothportal
templateDetails.xml index.php These two filenames and location must be matched exactly as this is how they are called by the Joomla core script.
In almost all templates, additional files are used. It is conventional (although not required by the core) to name and locate them as shown below: /JS_Smoothportal
template_thumbnail.png /css template_css.css /images logo.png
To add the template (again, copious tutorials exist) you go to the admin portion of your site and install the template by uploading the zip file. Note you can actually add the files individually (not in a zip) too. You have to put them in yoursite.com/templates. templateDetails.xmlThe templateDetails.xml must include all the files that are part of the template. It also includes information such as the author and copyright. Some of these are shown in the admin backend in the Template Manager An example xml file is shown below: <mosinstall type="template" version="1.0.x"
<name <creationDate <author <copyright <authorEmail <version <description <files <filename <filename <filename </files <images <filename <filename <filename </images <css <filename <filename </css </mosinstall Lets explain what some of these lines mean:
The index.phpWhat actually is in an index.php file? It is a combination of (X)HTML and PHP that determines everything about the layout and presentation of the pages. First we will look at a critical part of achieving valid templates, the DOCTYPE at the top of the index.php file. This bit of code that code goes at the very top of any web page. At the top of our page we have this in our template: <!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" lang="<?php echo _LANGUAGE; ? A web page DOCTYPE is part of the fundamental components of who a web page is shown by a browser, specifically, how that browser interprets CSS. To give you a sense, an observation from alistapart.com says: [information on W3C's site about doctypes is] "written by geeks for geeks. And when I say geeks, I donÙt mean ordinary web professionals like you and me. I mean geeks who make the rest of us look like Grandma on the first day SheÙs Got Mail.™" Anyway, there are several doctypes you can use. Basically, the doctype tells the browser how to interpret the page. Here the words "strict" and "transitional" start getting floated around (float:left and float:right usually). Essentially, ever since the WWW started, different browsers have had different levels of support for CSS. This means for example, that Internet Explorer won't understand the "min-width" command to set a minimum page width. To duplicate the effect you have to use "hacks" in the CSS. Strict means the html (or xhtml) will be interpreted exactly as dictated by standards. A transitional doctype means that the page will be allowed a few agreed upon differences to the standards. To complicate things, there is something called "quirks" mode. If the doctype is wrong, outdated, or not there, then the browser goes into quirks mode. This is an attempt to be backwards compatible, so Internet Explorer for example, will render the page pretending as if it was IE4. Unfortunately, people sometimes end up in quirks mode accidentally. It usually happens two ways:
Making a page standards compliant, where you see "valid xhtml" at the bottom of the page does not mean really difficult coding, or hard to understand tags. It merely means that the code you use matches the doctype you said it would. That's it! Nothing else. Designing your site to standards can on one level be reduced to saying what you do, and then doing what you say. Some useful links:
What else is in index.php?Let's look at the structure of the header first, we want to be as minimal as possible, but still have enough for a production site. The header information we will use is: <?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); ?
<!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" lang="<?php echo _LANGUAGE; ? <head <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ? <?php if ($my- <?php mosShowHead(); ? <script type="text/javascript" <!--http://www.bluerobot.com/web/css/fouc.asp-- <link href="/templates/<?php echo $cur_template; ? </head What does all that mean? <?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); ?
Makes sure that the file isn't being accessed directly.
<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); ?
<!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" lang="<?php echo _LANGUAGE; ? <head We talked about this above. The "<?php echo _LANGUAGE; ? <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?
What character set we are using, _ISO is a special constant defining the character set encoding to use. <?php
if ($my-
This is a script variable that is non-zero if a user is logged in to your site. If a user is logged in then the nominated WYSIWYG Editor is pre-loaded. You may, if you wish, always pre-load the Editor, but generally an anonymous visitor will not have the need to add content. This saves a little script overhead for normal browsing of your site. <?php mosShowHead(); ?
Header stuff that is set in the global configuration again. It includes the following tags (in a default installation):
<script type="text/javascript"
To stop a bug, that being a flash of un-styled content. Details courtesy of Blue Robot. Note this can be any script file, so if we add one, we can remove this line. <link href="/templates/<?php echo $cur_template; ?
This line links to the CSS file for the template. The PHP code <?php echo $cur_template; ? will return the name of the current template. This makes this line "portable". When you create a new template you can jsut copy it (along with the whole head code) and not worry about editing anything. As you will see later, in the temmplate_css.css file, we will use @import as a way to stop the site breaking with Netscape 4. Users of very old browsers won't be able to get the CSS sheet so will see our neat un styled content. If you wanted to cater to these older browsers, we would have too many CSS hacks, so we do this. A blank joomla template bodyThis will be very very easy! Ready? <body
<!-- 1 -- <!-- 2 -- <!-- 3 -- <!-- 4 -- <!-- 5 -- <!-- 6 -- <!-- 7 -- </body </html We have in a reasonably logical order:
The goal is to try and come as close to semantic markup as possible. From a web point of view, it means a page can be read by anyone, a browser, a spider or a screen reader. Semantic layout is the cornerstone of accessibility. Now its worth noting that what we have here really is only the potential for semantic layout. If one were to go ahead and put random modules in random locations, then you would have a mess. An important consideration for CMS sites, a template is only as good as the population of the content. It is this that often trips designers up when trying to validate their site. |
| Last Updated on Thursday, 28 August 2008 09:17 |
If you want online classes delivered to the comfort of your own home, then you need to join Joomlashack University - an affordable online Joomla training course taught by the world's leading experts in Joomla education.
If you are struggling with Joomla and want expert help, then fill out the form below. We'll send you some more information and you'll be first in line join the easiest and fastest way to learn Joomla.