Contao\Template::parse PHP Method

parse() public method

Parse the template file and return it as string
public parse ( ) : string
return string The template markup
    public function parse()
    {
        if ($this->strTemplate == '') {
            return '';
        }
        // HOOK: add custom parse filters
        if (isset($GLOBALS['TL_HOOKS']['parseTemplate']) && is_array($GLOBALS['TL_HOOKS']['parseTemplate'])) {
            foreach ($GLOBALS['TL_HOOKS']['parseTemplate'] as $callback) {
                $this->import($callback[0]);
                $this->{$callback[0]}->{$callback[1]}($this);
            }
        }
        return $this->inherit();
    }

Usage Example

Example #1
0
 /**
  * Add a hook to modify the template output
  *
  * @return string The template markup
  */
 public function parse()
 {
     /** @var PageModel $objPage */
     global $objPage;
     // Adjust the output format
     if ($objPage->outputFormat != '') {
         $this->strFormat = $objPage->outputFormat;
     }
     $strBuffer = parent::parse();
     // HOOK: add custom parse filters
     if (isset($GLOBALS['TL_HOOKS']['parseFrontendTemplate']) && is_array($GLOBALS['TL_HOOKS']['parseFrontendTemplate'])) {
         foreach ($GLOBALS['TL_HOOKS']['parseFrontendTemplate'] as $callback) {
             $this->import($callback[0]);
             $strBuffer = $this->{$callback[0]}->{$callback[1]}($strBuffer, $this->strTemplate);
         }
     }
     return $strBuffer;
 }