Template Code Comparison of J1.5 and J3.x: Difference between revisions
From Joomla! Documentation
mNo edit summary |
Some markup changes. |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<translate> | <translate> | ||
<!--T:1--> | <!--T:1--> | ||
The table below is a quick reference of code differences between a Joomla 1.5 and Joomla 3.x template's | 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> | </translate> | ||
| Line 10: | Line 10: | ||
'''Description'''</translate> | '''Description'''</translate> | ||
! <translate><!--T:3--> | ! <translate><!--T:3--> | ||
'''In a 1.5 Template(index.php)''' you might see</translate> | '''In a 1.5 Template (''index.php'')''' you might see</translate> | ||
! <translate><!--T:4--> | ! <translate><!--T:4--> | ||
'''Recommended J3.x Template(index.php) code'''</translate> | '''Recommended J3.x Template (''index.php'') code'''</translate> | ||
|- | |- | ||
| <translate><!--T:5--> | | <translate><!--T:5--> | ||
| Line 36: | Line 36: | ||
|- | |- | ||
| <translate><!--T:9--> | | <translate><!--T:9--> | ||
Retrieve HTML headers from Joomla</translate> | |||
| <pre><jdoc:include type="head" /></pre> | | <pre><jdoc:include type="head" /></pre> | ||
| <translate><!--T:10--> | | <translate><!--T:10--> | ||
| Line 42: | Line 42: | ||
|- | |- | ||
| <translate><!--T:11--> | | <translate><!--T:11--> | ||
Retrieve the Sitename</translate> | |||
| <pre>$mainframe->getCfg('sitename');</pre> | | <pre>$mainframe->getCfg('sitename');</pre> | ||
| <pre>$app->get('sitename');</pre> | | <pre>$app->get('sitename');</pre> | ||
| Line 84: | Line 84: | ||
ID</translate> | ID</translate> | ||
|<pre>JRequest::getVar( 'id' )</pre> | |<pre>JRequest::getVar( 'id' )</pre> | ||
|<translate>With alias:</translate><pre>$app->input->getString('id');</pre> | |<translate><!--T:32--> | ||
<translate>Only ID:</translate><pre>$app->input->getInt('id');</pre> | With alias:</translate><pre>$app->input->getString('id');</pre> | ||
<translate><!--T:33--> | |||
Only ID:</translate><pre>$app->input->getInt('id');</pre> | |||
|- | |- | ||
| <translate><!--T:20--> | | <translate><!--T:20--> | ||
| Line 123: | Line 125: | ||
'''No change'''</translate> | '''No change'''</translate> | ||
<translate><!--T:28--> | <translate><!--T:28--> | ||
However, use of | However, use of ''$this->'' is equivalent.</translate> | ||
|- | |- | ||
|- | |- | ||
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 |