Actions

Difference between revisions of "Creating a basic index file"

From Joomla! Documentation

(System CSS files are not linked to automatically using the jdoc include head, so added info about that. Also added the echo this template code.)
m (Applied Geshi tags for syntax highlighting.)
Line 3: Line 3:
 
Lets start at the top:
 
Lets start at the top:
  
<pre>
+
<source lang="php">
 
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
 
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
Line 9: Line 9:
 
<html xmlns="http://www.w3.org/1999/xhtml"  
 
<html xmlns="http://www.w3.org/1999/xhtml"  
 
   xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
 
   xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
</pre>
+
</source>
 
The first line stops naughty people looking at your coding and getting up to bad things. The second tells the browser (and webbots) 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. The second tells the browser (and webbots) what sort of page it is. The third line says what language the site is in.
  
 
Now the header for real:
 
Now the header for real:
  
<pre>
+
<source lang="php">
 
<head>
 
<head>
 
<jdoc:include type="head" />
 
<jdoc:include type="head" />
Line 21: Line 21:
 
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/css/style.css" type="text/css" />
 
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/css/style.css" type="text/css" />
 
</head>
 
</head>
</pre>
+
</source>
  
 
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.  
Line 28: Line 28:
  
 
Now for the main body:
 
Now for the main body:
<pre>
+
<source lang="php">
 
<body>
 
<body>
 
<jdoc:include type="modules" name="top" />  
 
<jdoc:include type="modules" name="top" />  
Line 34: Line 34:
 
<jdoc:include type="modules" name="bottom" />
 
<jdoc:include type="modules" name="bottom" />
 
</body>
 
</body>
</pre>
+
</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]].   

Revision as of 10:58, 28 April 2009

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.

Lets start at the top:

<?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 tells the browser (and webbots) what sort of page it is. The third line says what language the site is in.

Now the header for real:

<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/style.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 style.css and is located in the css folder).


Now for the main body:

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

Finish it off - one last bit:

</html>

View the full source code of this template.