Actions

Difference between revisions of "Creating a basic index file"

From Joomla! Documentation

m (Adjusted link after page move)
Line 1: Line 1:
 
The <tt>index.php</tt> 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.
 
The <tt>index.php</tt> 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.
  
Let's start at the top:
+
A Joomla 1.5 template begins with the following lines:
  
 
<source lang="php">
 
<source lang="php">
Line 10: Line 10:
 
   xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
 
   xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
 
</source>
 
</source>
The first line stops naughty people looking at your coding and getting up to bad things. The second tells the browser (and [[wikipedia:Web crawler|web crawlers]]) what sort of page it is. The third line says what language the site is in.
+
The first line stops naughty people looking at your coding and getting up to bad things.  
  
Now the header for real:
+
The second line is the doctype which tells the browser (and [[wikipedia:Web crawler|web crawlers]]) what sort of page it is. This doctype is xhtml 1.0 but you can also change this whole line to:
 +
 
 +
<source lang="php">
 +
<!DOCTYPE HTML>
 +
</source>
 +
 
 +
Which will make the page html5 instead of "xhtml 1.0 transitional" which will be a bit more up to date. It'll also ensure that you have access to a few new pieces of html code not featured in xhtml 1.0. You should be aware that this will not work in internet explorer 8 or earlier without a hack so unless you know how to add the hack you should leave it as xhtml 1.0.
 +
 
 +
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==
  
 
<source lang="php">
 
<source lang="php">
Line 24: Line 34:
  
 
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 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 <tt>template.css</tt> and is located in the <tt>''css''</tt> folder).
+
The rest creates links to two system style sheets and to your own style sheet (if it's named <tt>template.css</tt> and is located in the <tt>''css''</tt> 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==
  
Now for the main body:
 
 
<source lang="php">
 
<source lang="php">
 
<body>
 
<body>
Line 35: Line 46:
 
</source>
 
</source>
  
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" [[Screen.modules.edit.15#Details|module position]].
+
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" [[Screen.modules.edit.15#Details|module position]].  
 +
 
 +
==Module Positions==
 +
 
 +
Above the line which says name="top" adds a module position which is called top and allows Joomla to place modules into this section of the template. The type="component" line contains all articles and main content 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.
  
 
Finish it off - one last bit:
 
Finish it off - one last bit:
Line 43: Line 60:
 
<noinclude>View the [[Basic template index file|full source code]] of this template.</noinclude>
 
<noinclude>View the [[Basic template index file|full source code]] of this template.</noinclude>
 
[[Category:Tutorials]][[Category:Template Development]]
 
[[Category:Tutorials]][[Category:Template Development]]
 +
 +
==Custom Images==
 +
 +
If you want to add any images to the template you can do so like this:
 +
<source lang="php">
 +
<img src="<?php echo $thebaseurl; ?>/images/stories/myimage.png" alt="Custom image" class="customImage" />
 +
</source>
 +
 +
Here the $baseurl variable will fill in the path to your template for you.
 +
 +
==Custom CSS==
 +
 +
You can add custom css like this:
 +
 +
<source lang="php">
 +
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles.css" type="text/css" />
 +
</source>
 +
 +
Every file which is added must have a line in the templateDetails.xml file for the template.

Revision as of 08:26, 8 September 2011

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.

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 first line stops naughty people looking at your coding and getting up to bad things.

The second line is the doctype which tells the browser (and web crawlers) what sort of page it is. This doctype is xhtml 1.0 but you can also change this whole line to:

<!DOCTYPE HTML>

Which will make the page html5 instead of "xhtml 1.0 transitional" which will be a bit more up to date. It'll also ensure that you have access to a few new pieces of html code not featured in xhtml 1.0. You should be aware that this will not work in internet explorer 8 or earlier without a hack so unless you know how to add the hack you should leave it as xhtml 1.0.

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.

Contents

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>

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, 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.

Module Positions

Above the line which says name="top" adds a module position which is called top and allows Joomla to place modules into this section of the template. The type="component" line contains all articles and main content 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.

Finish it off - one last bit:

</html>

View the full source code of this template.

Custom Images

If you want to add any images to the template you can do so like this:

<img src="<?php echo $thebaseurl; ?>/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="<?php echo $this->baseurl ?>/templates/<?php echo $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.