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

From Joomla! Documentation

m Adjusted input filters to match type. Changed getCfg to get because it's deprecated.
MATsxm (talk | contribs)
mNo edit summary
Line 1: Line 1:
<noinclude><languages /></noinclude>
<translate>
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.
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.
</translate>


{| class="wikitable"
{| class="wikitable"
! '''Description'''
! <translate>'''Description'''</translate>
! '''In a 1.5 Template(index.php)''' you might see
! <translate>'''In a 1.5 Template(index.php)''' you might see</translate>
! '''Recommended J3.x Template(index.php) code'''
! <translate>'''Recommended J3.x Template(index.php) code'''</translate>
|-
|-
| First Line
| <translate>First Line</translate>
| <code><?php defined( '_JEXEC' ) or die( 'Restricted access' );?></code>  
| <code><?php defined( '_JEXEC' ) or die( 'Restricted access' );?></code>  
| '''No change'''
| <translate>'''No change'''</translate>
|-
|-
| DOCTYPE
| DOCTYPE
Line 16: Line 20:
<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>
<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>Access to Joomla Framework</translate>
| <pre>$app = JFactory::getApplication(); OR  
| <pre>$app = JFactory::getApplication(); OR  
require_once (‘includes/../framework.php' );
require_once (‘includes/../framework.php' );
$mainframe =& JFactory::getApplication('site');</pre>
$mainframe =& JFactory::getApplication('site');</pre>
| '''No change''' but needs to look like this:  
| <translate>'''No change''' but needs to look like this:</translate>
<pre>$app = JFactory::getApplication();</pre>
<pre>$app = JFactory::getApplication();</pre>
|-
|-
| Retreive HTML headers from Joomla
| <translate>Retreive HTML headers from Joomla</translate>
| <pre><jdoc:include type="head" /></pre>
| <pre><jdoc:include type="head" /></pre>
| '''No change'''
| <translate>'''No change'''</translate>
|-
|-
| Retreive the Sitename
| <translate>Retreive the Sitename</translate>
| <pre>$mainframe->getCfg('sitename');</pre>
| <pre>$mainframe->getCfg('sitename');</pre>
| <pre>$app->get('sitename');</pre>
| <pre>$app->get('sitename');</pre>
|-
|-
| Retrieve Error Codes
| <translate>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>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>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>Active Language</translate>
|<pre>$this->language;</pre>
|<pre>$this->language;</pre>
|<pre>$doc->language;</pre>
|<pre>$doc->language;</pre>
|-
|-
| View
| <translate>View</translate>
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>JRequest::getVar( 'view' )</pre>
|<pre>$app->input->getCmd('view');</pre>
|<pre>$app->input->getCmd('view');</pre>
|-
|-
| Task
| <translate>Task</translate>
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>JRequest::getVar( 'task' )</pre>
|<pre>$app->input->getCmd('task');</pre>
|<pre>$app->input->getCmd('task');</pre>
|-
|-
| Layout
| <translate>Layout</translate>
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>JRequest::getVar( 'layout' )</pre>
|<pre>$app->input->getString('layout', 'default');</pre>
|<pre>$app->input->getString('layout', 'default');</pre>
|-
|-
| ID
| <translate>ID</translate>
|<pre>JRequest::getVar( 'id' )</pre>
|<pre>JRequest::getVar( 'id' )</pre>
|With alias:<pre>$app->input->getString('id');</pre>
|With alias:<pre>$app->input->getString('id');</pre>
Only ID:<pre>$app->input->getInt('id');</pre>
Only ID:<pre>$app->input->getInt('id');</pre>
|-
|-
| Homepage detection
| <translate>Homepage detection</translate>
|<pre><?php if(JRequest::getVar( 'view' ) == 'frontpage') ?></pre>
|<pre><?php if(JRequest::getVar( 'view' ) == 'frontpage') ?></pre>
|<pre><?php $menu = $app->getMenu();
|<pre><?php $menu = $app->getMenu();
if($menu->getActive() == $menu->getDefault()) ?></pre>
if($menu->getActive() == $menu->getDefault()) ?></pre>
|-
|-
| Main Content  
| <translate>Main Content</translate>
| <pre><jdoc:include type="component" /></pre>
| <pre><jdoc:include type="component" /></pre>
| '''No change'''
| <translate>'''No change'''</translate>
|-
|-
| Modules & Positions
| <translate>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>'''No change'''</translate>
|-
|-
| Retrieve Base URL
| <translate>Retrieve Base URL</translate>
|<pre>$url = clone(JURI::getInstance());
|<pre>$url = clone(JURI::getInstance());
echo $this->baseurl;  
echo $this->baseurl;  
Line 87: Line 91:
</pre>
</pre>
|-
|-
| Access to Document Page Classes
| <translate>Access to Document Page Classes</translate>
|<pre>$doc = JFactory::getDocument();
|<pre>$doc = JFactory::getDocument();
</pre>
</pre>
|'''No change'''  
|<translate>'''No change'''</translate>
However, use of "$this->" is equivalent.
<translate>However, use of "$this->" is equivalent.</translate>
|-
|-
|-
|-
| Access to Template Parameters
| <translate>Access to Template Parameters</translate>
|<pre>echo $this->params->get('colorVariation');
|<pre>echo $this->params->get('colorVariation');
</pre>
</pre>
| '''No change'''
| <translate>'''No change'''</translate>
|-
|-
|}
|}


<noinclude>
<noinclude>
<translate>
[[Category:Template Development]]
[[Category:Template Development]]
[[Category:Migration]]
[[Category:Migration]]
</translate>
</noinclude>
</noinclude>

Revision as of 18:50, 22 January 2015

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();
Retreive HTML headers from Joomla
<jdoc:include type="head" />
No change
Retreive 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