/** * Parse the template file and return it as string * * @return string The template markup */ public function parse() { $strBuffer = ''; // Start with the template itself $this->strParent = $this->strTemplate; // Include the parent templates while ($this->strParent !== null) { $strCurrent = $this->strParent; $strParent = $this->strDefault ?: $this->getTemplate($this->strParent, $this->strFormat); // Reset the flags $this->strParent = null; $this->strDefault = null; ob_start(); include $strParent; // Capture the output of the root template if ($this->strParent === null) { $strBuffer = ob_get_contents(); } elseif ($this->strParent == $strCurrent) { $this->strDefault = \TemplateLoader::getDefaultPath($this->strParent, $this->strFormat); } ob_end_clean(); } // Reset the internal arrays $this->arrBlocks = array(); // Add start and end markers in debug mode if (\Config::get('debugMode')) { $strRelPath = str_replace(TL_ROOT . '/', '', $this->getTemplate($this->strTemplate, $this->strFormat)); $strBuffer = "\n<!-- TEMPLATE START: {$strRelPath} -->\n{$strBuffer}\n<!-- TEMPLATE END: {$strRelPath} -->\n"; } return $strBuffer; }
/** * Find a particular template file and return its path * * @param string $strTemplate The name of the template * @param string $strFormat The file extension * @param boolean $blnDefault If true, the default template path is returned * * @return string The path to the template file */ protected function getTemplatePath($strTemplate, $strFormat = 'html5', $blnDefault = false) { if ($blnDefault) { return \TemplateLoader::getDefaultPath($strTemplate, $strFormat); } return \Controller::getTemplate($strTemplate, $strFormat); }