Template Code Comparison of J1.5 and J3.x

From Joomla! Documentation

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎Nederlands

The table below is a quick reference of code differences between a Joomla 1.5 and Joomla 3.x template's index.php file.

Description In a 1.5 Template (index.php) you might see Recommended J3.x Template (index.php) code
First Line <?php defined( '_JEXEC' ) or die( 'Restricted access' );?> No change
<?php echo '<?xml version="1.0" encoding="utf-8"?'.'>'; ?><!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; ?>" dir="<?php echo $this->direction; ?>" >
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
Access to Joomla Framework
$app = JFactory::getApplication(); OR 
require_once (‘includes/../framework.php' );
$mainframe =& JFactory::getApplication('site');
No change but needs to look like this:
$app = JFactory::getApplication();
Retreive HTML headers from Joomla
<jdoc:include type="head" />
No change
Retreive the Sitename
Retrieve Error Codes
Retrieve Error Messages
Retrieve System Messages
<jdoc:include type="message" />
Active Language
JRequest::getVar( 'view' )
JRequest::getVar( 'task' )
JRequest::getVar( 'layout' )
$app->input->getString('layout', 'default');
JRequest::getVar( 'id' )
With alias:
Only ID:
Homepage detection
<?php if(JRequest::getVar( 'view' ) == 'frontpage') ?>
<?php $menu = $app->getMenu();
if($menu->getActive() == $menu->getDefault()) ?>
Main Content
<jdoc:include type="component" />
No change
Modules & Positions
<jdoc:include type="modules" name="right" style="xhtml" />
No change
Retrieve Base URL
$url = clone(JURI::getInstance());
echo $this->baseurl; 
Access to Document Page Classes
$doc = JFactory::getDocument();
No change

However, use of "$this->" is equivalent.

Access to Template Parameters
echo $this->params->get('colorVariation');
No change