コード例 #1
0
 public function render($name, $params = [])
 {
     $params = $this->mergeParams($name, $params);
     $template = $this->resolver->resolve($name);
     if (!$template) {
         throw new Exception\TemplateNotFoundException("Couldn't resolve '{$name}'");
     }
     if ($template->isCompiled()) {
         $compiled = (string) $template;
     } else {
         try {
             $compiled = $this->handlebars->precompile((string) $template);
         } catch (\V8JsScriptException $e) {
             throw new Exception\TemplateCompilationException("Error compiling '{$name}'", 0, $e);
         }
         if ($this->resolver instanceof SavingResolverInterface) {
             $this->resolver->save($template->getKey(), $compiled);
         }
     }
     try {
         $template = $this->handlebars->template($compiled);
         return $template($params);
     } catch (\V8JsScriptException $e) {
         throw new Exception\TemplateExecutionException("Error running '{$name}'", 0, $e);
     }
 }
コード例 #2
0
 /**
  * We don't cache PHP helpers ourselves, but rely on bytecode cache instead
  * @param Handlebars $handlebars
  * @param array $helpers
  */
 private function injectPhpHelpers(Handlebars $handlebars, $helpers)
 {
     $phpHelpers = [];
     foreach ($helpers as $fileName) {
         $helper = (include $fileName);
         $handlebars->registerHelper($this->getName($fileName), $helper);
     }
     $handlebars->registerHelper($phpHelpers);
 }
コード例 #3
0
 public function testLogDebug()
 {
     $hb = Handlebars::create();
     $logs = [];
     $logger = $this->getLogger($logs)->reveal();
     $hb->setLogger($logger);
     $template = $hb->compile('{{ log "Debug!" level="debug" }}');
     $result = $template([], ['data' => ['level' => LogLevel::DEBUG]]);
     $this->assertContains("Debug!", $logs[LogLevel::DEBUG]);
 }