コード例 #1
0
 /**
  * @see \Ableron\Core\Template\Plugins\Interfaces\FunctionPluginInterface::execute()
  */
 public function execute(TemplateRenderer $templateRenderer, $tagArguments)
 {
     // read arguments
     $templateFile = isset($tagArguments['templateFile']) ? $tagArguments['templateFile'] : $tagArguments[0];
     $variables = isset($tagArguments['variables']) ? $tagArguments['variables'] : array();
     $sandboxMode = isset($tagArguments['sandboxMode']) ? $tagArguments['sandboxMode'] : false;
     // check for argument "templateFile"
     if (StringUtil::isNullOrEmpty($templateFile)) {
         throw new SystemException('Missing argument "templateFile" in tag {include}', 0, E_USER_ERROR, __FILE__, __LINE__);
     }
     // return output of the rendered template
     return $templateRenderer->getTemplateHandler()->render(TemplateHelper::getAbsoluteTemplateFilePath($templateFile, $templateRenderer->getCurrentTemplatePath()), $sandboxMode ? $variables : array_merge($templateRenderer->getCurrentVariables(), $variables), true, $templateRenderer);
 }
コード例 #2
0
 /**
  * Returns the content of the given template file.
  *
  * Throws an exception in case the the template file does not exist.
  *
  * @param string $templateFile Path of the template to read
  * @throws \Ableron\Core\Exception\SystemException
  * @return string
  */
 private function readTemplate($templateFile)
 {
     // determine absolute path of the template
     $finalTemplateFile = TemplateHelper::getAbsoluteTemplateFilePath($templateFile, $this->currentTemplatePath);
     // check whether the template exists
     if (!is_file($finalTemplateFile)) {
         throw new SystemException(sprintf('Template does not exist: %s', $templateFile), 0, E_USER_ERROR, __FILE__, __LINE__);
     }
     // set new template path and template name based on final template file
     $this->currentTemplatePath = pathinfo($finalTemplateFile, PATHINFO_DIRNAME);
     $this->currentTemplateName = basename($finalTemplateFile);
     // return the template
     return file_get_contents($finalTemplateFile);
 }