english/libraries/joomla/application/component/view.php
/**
	 * Load a template file -- first look in the templates folder for an override
	 *
	 * @param   string   The name of the template source file ...
	 * 					automatically searches the template paths and compiles as needed.
	 * @return  string   The output of the the template script.
	 */
Load a template file -- first look in the templates folder for an override
@param   string   The name of the template source file
automatically searches the template paths and compiles as needed.
@return  string   The output of the the template script.
Load a template file -- first look in the templates folder for an override @param string The name of the template source file automatically searches the template paths and compiles as needed . @return string The output of the the template script .
public function loadTemplate($tpl = null)
	{
		$this->_output = null;
		$template = JFactory::getApplication()->getTemplate();
		$layout = $this->getLayout();
		$layoutTemplate = $this->getLayoutTemplate();
		$file = isset($tpl) ? $layout.'_'.$tpl : $layout;
		$file = preg_replace('/[^A-Z0-9_\.-]/i', '', $file);
		$tpl  = isset($tpl)? preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl) : $tpl;
		$lang	= JFactory::getLanguage();
			$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);
		if (isset($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template)
		{
			$this->_path['template'] = str_replace($template, $layoutTemplate, $this->_path['template']);
		}
		jimport('joomla.filesystem.path');
		$filetofind	= $this->_createFileName('template', array('name' => $file));
		$this->_template = JPath::find($this->_path['template'], $filetofind);
		if ($this->_template == false)
		{
			$filetofind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl)));
			$this->_template = JPath::find($this->_path['template'], $filetofind);
		}
		if ($this->_template != false)
		{
			unset($tpl);
			unset($file);
			if (isset($this->this)) {
				unset($this->this);
			}
			ob_start();
			include $this->_template;
			$this->_output = ob_get_contents();
			ob_end_clean();
			return $this->_output;
		}
		else {
			return JError::raiseError(500, JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file));
		}
	}
public function loadTemplate ( $ tpl = null ) { $ this -> _output = null ; $ template = JFactory :: getApplication ( ) -> getTemplate ( ) ; $ layout = $ this -> getLayout ( ) ; $ layoutTemplate = $ this -> getLayoutTemplate ( ) ; $ file = isset ( $ tpl ) ? $ layout . '_' . $ tpl : $ layout ; $ file = preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , $ file ) ; $ tpl = isset ( $ tpl ) ? preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , $ tpl ) : $ tpl ; $ lang = JFactory :: getLanguage ( ) ; $ 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 ) ; if ( isset ( $ layoutTemplate ) && $ layoutTemplate != '_' && $ layoutTemplate != $ template ) { $ this -> _path [ 'template' ] = str_replace ( $ template , $ layoutTemplate , $ this -> _path [ 'template' ] ) ; } jimport ( 'joomla.filesystem.path' ) ; $ filetofind = $ this -> _createFileName ( 'template' , array ( 'name' => $ file ) ) ; $ this -> _template = JPath :: find ( $ this -> _path [ 'template' ] , $ filetofind ) ; if ( $ this -> _template == false ) { $ filetofind = $ this -> _createFileName ( '' , array ( 'name' => 'default' . ( isset ( $ tpl ) ? '_' . $ tpl : $ tpl ) ) ) ; $ this -> _template = JPath :: find ( $ this -> _path [ 'template' ] , $ filetofind ) ; } if ( $ this -> _template != false ) { unset ( $ tpl ) ; unset ( $ file ) ; if ( isset ( $ this -> this ) ) { unset ( $ this -> this ) ; } ob_start ( ) ; include $ this -> _template ; $ this -> _output = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ this -> _output ; } else { return JError :: raiseError ( 500 , JText :: sprintf ( 'JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND' , $ file ) ) ; } }
Load a template file -- first look in the templates folder for an override
 @param   string   The name of the template source file ...
                                      automatically searches the template paths and compiles as needed.
Load a template file -- first look in the templates folder for an override @param string The name of the template source file ... automatically searches the template paths and compiles as needed .
// clear prior output // Create the template file name based on the layout // Clean the file name // Load the language file for the template // Change the template folder if alternative layout is in different template // Load the template script // If alternate layout can't be found, fall back to default layout // Unset so as not to introduce into template scope // Never allow a 'this' property // Start capturing output into a buffer // Include the requested template filename in the local scope // (this will execute the view logic). // Done with the requested template; get the buffer and // clear it.