JView/loadTemplate: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Load a template file -- first look in the templates folder for an override
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JView/lo... |
m preparing for archive only |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 32: | Line 32: | ||
===Source Body=== | ===Source Body=== | ||
<source lang="php"> | <source lang="php"> | ||
function loadTemplate($tpl = null) | function loadTemplate( $tpl = null) | ||
{ | { | ||
global $mainframe, $option; | |||
// clear prior output | // clear prior output | ||
$this->_output = null; | $this->_output = null; | ||
| Line 73: | Line 75: | ||
} | } | ||
else { | else { | ||
return JError::raiseError(500, 'Layout "' . $file . '" not found'); | return JError::raiseError( 500, 'Layout "' . $file . '" not found' ); | ||
} | } | ||
} | } | ||
| Line 79: | Line 81: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=loadTemplate | category=loadTemplate | ||
category=JView | category=JView | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 01:16, 25 March 2017
Description
Load a template file -- first look in the templates folder for an override
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
loadTemplate($tpl=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $tpl | null | $tpl The name of the template source file ... automatically searches the template paths and compiles as needed. |
Returns
string The output of the the template script.
Defined in
libraries/joomla/application/component/view.php
Importing
jimport( 'joomla.application.component.view' );
Source Body
function loadTemplate( $tpl = null)
{
global $mainframe, $option;
// clear prior output
$this->_output = null;
//create the template file name based on the layout
$file = isset($tpl) ? $this->_layout.'_'.$tpl : $this->_layout;
// clean the file name
$file = preg_replace('/[^A-Z0-9_\.-]/i', '', $file);
$tpl = preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl);
// load the template script
jimport('joomla.filesystem.path');
$filetofind = $this->_createFileName('template', array('name' => $file));
$this->_template = JPath::find($this->_path['template'], $filetofind);
if ($this->_template != false)
{
// unset so as not to introduce into template scope
unset($tpl);
unset($file);
// never allow a 'this' property
if (isset($this->this)) {
unset($this->this);
}
// start capturing output into a buffer
ob_start();
// include the requested template filename in the local scope
// (this will execute the view logic).
include $this->_template;
// done with the requested template; get the buffer and
// clear it.
$this->_output = ob_get_contents();
ob_end_clean();
return $this->_output;
}
else {
return JError::raiseError( 500, 'Layout "' . $file . '" not found' );
}
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples