Difference between revisions of "Creating a basic index file"

From Joomla! Documentation

m
m
Line 5: Line 5:
 
<pre>
 
<pre>
 
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
 
<?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">
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
+
    "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; ?>" >
 
</pre>
 
</pre>
 
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.
Line 19: Line 21:
 
</pre>
 
</pre>
  
The first line gets Joomla to put the correct header information in. The second creates a link to your style sheet. You will need to change this to the directory name that you chose.
+
The first line gets Joomla to put the correct header information in. This includes the page title, meta information as well as system style sheets and JavaScript.
 +
The second creates a link to your style sheet. You will need to change this to the directory name that you chose.
  
 
Now for the main body:
 
Now for the main body:
 
 
<pre>
 
<pre>
 
<body>
 
<body>
Line 31: Line 33:
 
</pre>
 
</pre>
  
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.   
+
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]].   
  
 
Finish it off - one last bit:
 
Finish it off - one last bit:
 
 
<pre>
 
<pre>
 
</html>
 
</html>
 
</pre>
 
</pre>
 +
<noinclude>View the [[Testing the template|full source code]] of this template.</noinclude>

Revision as of 09:18, 2 June 2008

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 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/mynewtemplate/css/css.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 style sheets and JavaScript. The second creates a link to your style sheet. You will need to change this to the directory name that you chose.

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.