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

From Joomla! Documentation

Tom Hutchison (talk | contribs)
m update
Cmb (talk | contribs)
Some markup changes.
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
The table below is a quick reference of code differences between a Joomla 1.5 and Joomla 3.x template's <code>index.php</code> file.
<noinclude><languages /></noinclude>
 
<translate>
<!--T:1-->
The table below is a quick reference of code differences between a Joomla 1.5 and Joomla 3.x template's ''index.php'' file.
</translate>


{| class="wikitable"
{| class="wikitable"
! '''Description'''
! <translate><!--T:2-->
! '''In a 1.5 Template(index.php)''' you might see
'''Description'''</translate>
! '''Recommended J3.x Template(index.php) code'''
! <translate><!--T:3-->
'''In a 1.5 Template (''index.php'')''' you might see</translate>
! <translate><!--T:4-->
'''Recommended J3.x Template (''index.php'') code'''</translate>
|-
|-
| First Line
| <translate><!--T:5-->
First Line</translate>
| <code><?php defined( '_JEXEC' ) or die( 'Restricted access' );?></code>  
| <code><?php defined( '_JEXEC' ) or die( 'Restricted access' );?></code>  
| '''No change'''
| <translate><!--T:6-->
'''No change'''</translate>
|-
|-
| DOCTYPE
| DOCTYPE
| <pre><!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <pre><?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="en" lang="en" dir="ltr"></pre>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" ></pre>
|<pre><!DOCTYPE html>
|<pre><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="en" lang="en" dir="ltr"></pre>
<html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>"></pre>
|-
|-
| Access to Joomla Framework
| <translate><!--T:7-->
| <pre>$url = clone(JURI::getInstance());</pre>
Access to Joomla Framework</translate>
| <pre><?php $app = Jfactory::getApplication();
| <pre>$app = JFactory::getApplication(); OR
doc = factory::getDocument();?></pre>
require_once (‘includes/../framework.php' );
$mainframe =& JFactory::getApplication('site');</pre>
| <translate><!--T:8-->
'''No change''' but needs to look like this:</translate>
<pre>$app = JFactory::getApplication();</pre>
|-
|-
| Retreive HTML headers from Joomla
| <translate><!--T:9-->
Retrieve HTML headers from Joomla</translate>
| <pre><jdoc:include type="head" /></pre>
| <pre><jdoc:include type="head" /></pre>
| '''No change'''
| <translate><!--T:10-->
'''No change'''</translate>
|-
|-
| Retreive the Sitename
| <translate><!--T:11-->
| <pre><?php echo $mainframe-> getCfg('sitename');?></pre>
Retrieve the Sitename</translate>
| <pre><?php $app->getCfg('sitename');?></pre>
| <pre>$mainframe->getCfg('sitename');</pre>
| <pre>$app->get('sitename');</pre>
|-
|-
| Retrieve Error Codes
| <translate><!--T:12-->
Retrieve Error Codes</translate>
|<pre>$this->error->code</pre>
|<pre>$this->error->code</pre>
|<pre>$this->error->getCode();</pre>
|<pre>$this->error->getCode();</pre>
|-
|-
| Retrieve Error Messages
| <translate><!--T:13-->
Retrieve Error Messages</translate>
|<pre>$this->error->message</pre>
|<pre>$this->error->message</pre>
|<pre>$this->error->getMessage();</pre>
|<pre>$this->error->getMessage();</pre>
|-
|-
| Retrieve System Messages
| <translate><!--T:14-->
Retrieve System Messages</translate>
|<pre>$this->getBuffer('message')</pre>
|<pre>$this->getBuffer('message')</pre>
|<pre><jdoc:include type="message" /></pre>
|<pre><jdoc:include type="message" /></pre>
|-
|-
| Active Language
| <translate><!--T:15-->
|<pre><?php echo $this->language; ?></pre>
Active Language</translate>
|<pre><?php $this->language  = $doc->language; ?></pre>
|<pre>$this->language;</pre>
|<pre>$doc->language;</pre>
|-
|-
| View
| <translate><!--T:16-->
View</translate>
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>$view    = $app->input->getCmd('view', '');</pre>
|<pre>$app->input->getCmd('view');</pre>
|-
|-
| Task
| <translate><!--T:17-->
Task</translate>
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>$task = $app->input->getCmd('task', '');</pre>
|<pre>$app->input->getCmd('task');</pre>
|-
|-
| Layout
| <translate><!--T:18-->
Layout</translate>
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>$layout  = $app->input->getCmd('layout, '');</pre>
|<pre>$app->input->getString('layout', 'default');</pre>
|-
|-
| ID
| <translate><!--T:19-->
ID</translate>
|<pre>JRequest::getVar( 'id' )</pre>
|<pre>JRequest::getVar( 'id' )</pre>
|<pre>$id = $app->input->getCmd('layout, '');</pre>
|<translate><!--T:32-->
With alias:</translate><pre>$app->input->getString('id');</pre>
<translate><!--T:33-->
Only ID:</translate><pre>$app->input->getInt('id');</pre>
|-
|-
| Homepage detection
| <translate><!--T:20-->
|<pre>JRequest::getVar( 'view' ) == 'frontpage'</pre>
Homepage detection</translate>
|<pre><?php $menu = $app->getMenu(); ?>
|<pre><?php if(JRequest::getVar( 'view' ) == 'frontpage') ?></pre>
  <?php if($menu->getActive() == $menu-> getDefault()) { ?></pre>
|<pre><?php $menu = $app->getMenu();
if($menu->getActive() == $menu->getDefault()) ?></pre>
|-
|-
| Main Content  
| <translate><!--T:21-->
Main Content</translate>
| <pre><jdoc:include type="component" /></pre>
| <pre><jdoc:include type="component" /></pre>
| '''No change'''
| <translate><!--T:22-->
'''No change'''</translate>
|-
|-
| Modules & Positions
| <translate><!--T:23-->
Modules & Positions</translate>
|<pre><jdoc:include type="modules" name="right" style="xhtml" /></pre>
|<pre><jdoc:include type="modules" name="right" style="xhtml" /></pre>
| '''No change'''
| <translate><!--T:24-->
'''No change'''</translate>
|-
| <translate><!--T:25-->
Retrieve Base URL</translate>
|<pre>$url = clone(JURI::getInstance());
echo $this->baseurl;
JURI::root()*;
</pre>
|<pre>
JURI::base();
$this->baseurl;
</pre>
|-
| <translate><!--T:26-->
Access to Document Page Classes</translate>
|<pre>$doc = JFactory::getDocument();
</pre>
|<translate><!--T:27-->
'''No change'''</translate>
<translate><!--T:28-->
However, use of ''$this->'' is equivalent.</translate>
|-
|-
|-
| URL
| <translate><!--T:29-->
|<pre>JURI::root()*</pre>
Access to Template Parameters</translate>
|<pre>$this->baseurl</pre>
|<pre>echo $this->params->get('colorVariation');
</pre>
| <translate><!--T:30-->
'''No change'''</translate>
|-
|-
|}
|}


<noinclude>
<translate>
<!--T:31-->
[[Category:Template Development]]
[[Category:Template Development]]
[[Category:Migration]]
[[Category:Migration]]
</translate>
</noinclude>

Latest revision as of 22:30, 2 December 2022

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
<?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();
Retrieve HTML headers from Joomla
<jdoc:include type="head" />
No change
Retrieve the Sitename
$mainframe->getCfg('sitename');
$app->get('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
$this->language;
$doc->language;
View
JRequest::getVar( 'view' )
$app->input->getCmd('view');
Task
JRequest::getVar( 'task' )
$app->input->getCmd('task');
Layout
JRequest::getVar( 'layout' )
$app->input->getString('layout', 'default');
ID
JRequest::getVar( 'id' )
With alias:
$app->input->getString('id');
Only ID:
$app->input->getInt('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; 
JURI::root()*; 
JURI::base();
$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