Datareign

index.php is the only file that Joomla insists is present in a template.

It is where all the main logic of a template is stored and has to specify all the module and component display code. Although any JavaScript code would also be referenced here, it is probably a bad idea to include formatting and layout directives in this file.

Basic Functionality

A minimal Joomla index.php would look something like:

  <html>
  <head>
     <jdoc:include type="head" />
  </head>
  
  <body>
     <h1> This is a Joomla heading entry</h1>
  </body>
  </html>

Although Joomla will run this satisfactorily, it will actually produce no visible output in the browser. So, what is actually happening?

JDocument Class

The “jdoc” tag sets up a call to JDocument, which is a PHP class within the Joomla framework. The modifier ”:include” specifies a method within this class. Generally speaking, the include method is used for all output within Joomla templates.

JDocumentHTML Class

This provides access to the generated document text in a structured fashion. The most useful properties of this object are…

  • direction specifies the reading direction of output text.
  • template holds a path string that tells us where the template is stored.
  • title is the document title used for display, etc.
  • description a reprise of the HTML metadata describing the generated document.
  • link holds the base URL of the generated document.
  • language specifies the generated document's language code e.g. “en” for “English”.

JDocumentHTML methods include:

  • countmodules returns the number of modules active on the current page. If given the name of a module as a parameter, it will instead return the number of instances of that particular module, which are active on the page.

Using $this

Within a Joomla template, $this always returns a reference to a current instance of JDocumentHTML. Hence the statement

 <?php echo $this->template;?>

will print the current template's directory path.

Last modified: 2009/01/20 21:23