Example #1
0
 /**
  * @internal
  */
 public function __construct()
 {
     parent::__construct();
     $this->setTemplateDir(self::getSourcePath());
     $this->left_delimiter = '<!--{';
     $this->right_delimiter = '}-->';
 }
Example #2
0
File: Form.php Project: fem/spof
 /**
  * Render the form and return as HTML-string.
  *
  * @api
  *
  * @return string
  */
 public final function render()
 {
     $template = HtmlTemplate::getInstance();
     $template->assign('route', $this->route);
     $template->assign('routeContext', $this->routeContext);
     $template->assign('fieldsets', $this->fieldset);
     $template->assign('buttons', $this->button);
     return $template->fetch('form/form.tpl');
 }
Example #3
0
 /**
  * fetches a rendered Smarty template. Overrides Smarty_Internal_Compilerbase::fetch().
  *
  * @api
  *
  * @throws \ErrorException if a error occurred in the code triggered by the template
  * @throws \FeM\sPof\exception\SmartyTemplateException if the error occurred in a template
  *
  * @param string $template (optional) the resource handle of the template file or template object
  * @param mixed $cache_id (optional) cache id to be used with this template
  * @param mixed $compile_id (optional) compile id to be used with this template
  * @param object $parent (optional) next higher level of Smarty variables
  * @param bool $display (optional) true: display, false: fetch
  * @param bool $merge_tpl_vars (optional) if true parent template variables merged in to local scope
  * @param bool $no_output_filter (optional) if true do not run output filter
  *
  * @return string rendered template output
  */
 public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
 {
     try {
         if ($display) {
             Logger::getInstance()->addSmarty();
         }
         return parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
     } catch (\ErrorException $e) {
         if (strpos($e->getFile(), '.tpl.php') > 0) {
             $file = HtmlTemplate::getTemplateByCompilePath($e->getFile());
             $error_msg = str_replace('Undefined index: ', 'Unassigned variable: $', $e->getMessage()) . ' in File: ' . $file . ' in Compiled file ' . $e->getFile() . ':' . $e->getLine();
             $e = new SmartyTemplateException($error_msg, $file, $e);
         }
         throw $e;
     }
 }
Example #4
0
File: Logger.php Project: fem/spof
 /**
  * Add current smarty settings to the log.
  */
 public function addSmarty()
 {
     $vars = template\HtmlTemplate::getInstance()->getTemplateVars();
     foreach ($vars as &$var) {
         if ($var === '') {
             $var = '(empty)';
         } elseif ($var === false) {
             $var = '(bool: false)';
         } elseif ($var === true) {
             $var = '(bool: true)';
         } elseif ($var === null) {
             $var = '(nil)';
         }
     }
     ksort($vars);
     $this->debugBar->addCollector(new Collector\ConfigCollector($vars, 'Smarty'));
 }
Example #5
0
 /**
  * This function is the final step to render a website, it passes the final arguments to the template, including
  * all error messages, gathered so far. And finally flushes the website content.
  *
  * @api
  */
 public function display()
 {
     // minify js
     $jsFile = template\JavascriptTemplate::combine($this->jsFiles);
     if ($jsFile !== false) {
         $this->assign('customjsfile', [$jsFile]);
     } else {
         $this->assign('customjsfile', []);
     }
     // minify css
     $cssFile = template\CssTemplate::combine($this->cssFiles);
     if ($cssFile !== false) {
         $this->assign('customcssfile', [$cssFile]);
     } else {
         $this->assign('customcssfile', []);
     }
     // this code is not safe for use in different tabs
     foreach (Session::getErrorMsg() as $error) {
         $this->append('errors', ($error['field'] ? '"' . $error['field'] . '" - ' : '') . $error['content']);
     }
     foreach (Session::getSuccessMsg() as $success) {
         $this->append('success', $success);
     }
     // we need a relative dir from smarty templates
     template\HtmlTemplate::getInstance()->display('layout.tpl');
     // after we've displayed them, we may reset them
     Session::resetErrorMsg();
     Session::resetSuccessMsg();
 }
Example #6
0
 /**
  * Render this element.
  *
  * @api
  *
  * @return string
  */
 public function render()
 {
     try {
         $this->renderPrepare();
         return HtmlTemplate::getInstance()->fetch('form/html_tag.tpl');
     } catch (\Exception $e) {
         //Logger::getInstance()->exception($e);
         return '';
     }
 }