setTemplate() публичный Метод

public setTemplate ( Twig_Template $template ) : TemplateResponse
$template Twig_Template
Результат TemplateResponse
Пример #1
0
 /**
  * @param string $templateName
  * @param array  $context
  * @param array  $globals
  *
  * @return TemplateResponse
  */
 protected function createTestResponse($templateName, $context, $globals)
 {
     $app = $this->getApp();
     $template = $app['twig']->loadTemplate($templateName);
     $response = new TemplateResponse($template->render($context));
     $response->setTemplate($template)->setContext($context)->setGlobals($globals);
     return $response;
 }
Пример #2
0
 /**
  * Render a template, possibly store it in cache. Or, if applicable, return the cached result.
  *
  * @param string $templateFile Template file name
  * @param array  $context      Context variables
  * @param array  $globals      Global variables
  *
  * @return TemplateResponse
  */
 public function render($templateFile, $context = [], $globals = [])
 {
     $this->app['stopwatch']->start('bolt.render', 'template');
     /** @var Environment $twig */
     $twig = $this->app[$this->twigKey];
     /** @var Template $template */
     $template = $twig->loadTemplate($templateFile);
     foreach ($globals as $name => $value) {
         $twig->addGlobal($name, $value);
     }
     $html = $template->render($context);
     $response = new TemplateResponse($html);
     $response->setTemplate($template)->setContext($context)->setGlobals($globals);
     $this->app['stopwatch']->stop('bolt.render');
     return $response;
 }