Actions

API16

JView/loadTemplate

From Joomla! Documentation

< API16:JView
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Load a template file -- first look in the templates folder for an override

[Edit Descripton]

Description:JView/loadTemplate

Syntax

loadTemplate($tpl=null)
Parameter Name Default Value Description
$tpl null 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)
{
        // 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 language file for the template
        $lang = &JFactory::getLanguage();
        $app = &JFactory::getApplication();
        $template = $app->getTemplate();
                $lang->load('tpl_'.$template, JPATH_BASE, null, false, false)
        ||      $lang->load('tpl_'.$template, JPATH_THEMES."/$template", null, false, false)
        ||      $lang->load('tpl_'.$template, JPATH_BASE, $lang->getDefault(), false, false)
        ||      $lang->load('tpl_'.$template, JPATH_THEMES."/$template", $lang->getDefault(), false, false);
 
 
        // 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');
        }
}

[Edit See Also] SeeAlso:JView/loadTemplate

Examples

<CodeExamplesForm />