Template Code Comparison of J1.5 and J3.x: Difference between revisions

From Joomla! Documentation

Tom Hutchison (talk | contribs)
m no include
Removed variable assignments as they aren't necessary
Line 42: Line 42:
|-
|-
| Active Language
| Active Language
|<pre><?php echo $this->language; ?></pre>
|<pre><?php $this->language; ?></pre>
|<pre><?php $this->language  = $doc->language; ?></pre>
|<pre><?php $doc->language; ?></pre>
|-
|-
| View
| View
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>$view    = $app->input->getCmd('view', '');</pre>
|<pre>$app->input->getCmd('view', '');</pre>
|-
|-
| Task
| Task
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>$task = $app->input->getCmd('task', '');</pre>
|<pre>$app->input->getCmd('task', '');</pre>
|-
|-
| Layout
| Layout
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>$layout  = $app->input->getCmd('layout, '');</pre>
|<pre>$app->input->getCmd('layout, '');</pre>
|-
|-
| ID
| ID
|<pre>JRequest::getVar( 'id' )</pre>
|<pre>JRequest::getVar( 'id' )</pre>
|<pre>$id = $app->input->getCmd('layout, '');</pre>
|<pre>$app->input->getCmd('layout, '');</pre>
|-
|-
| Homepage detection
| Homepage detection

Revision as of 13:49, 31 October 2014

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
DOCTYPE
<!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="en" lang="en" dir="ltr">
<!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
$url = clone(JURI::getInstance());
$app = Jfactory::getApplication();
$doc = Jfactory::getDocument();
Retreive HTML headers from Joomla
<jdoc:include type="head" />
No change
Retreive the Sitename
<?php echo $mainframe-> getCfg('sitename');?>
<?php $app->getCfg('sitename');?>
Retrieve Error Codes
$this->error->code
$this->error->getCode();
Retrieve Error Messages
$this->error->message
$this->error->getMessage();
Retrieve System Messages
$this->getBuffer('message')
<jdoc:include type="message" />
Active Language
<?php $this->language; ?>
<?php $doc->language; ?>
View
JRequest::getVar( 'view' )
$app->input->getCmd('view', '');
Task
JRequest::getVar( 'task' )
$app->input->getCmd('task', '');
Layout
JRequest::getVar( 'layout' )
$app->input->getCmd('layout, '');
ID
JRequest::getVar( 'id' )
$app->input->getCmd('layout, '');
Homepage detection
JRequest::getVar( 'view' ) == 'frontpage'
<?php $menu = $app->getMenu(); ?>
  <?php 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
URL
JURI::root()*
$this->baseurl