public function runTest()
 {
     $loader = new FilesystemLoader(__DIR__ . '/../views/%name%');
     $templating = new DelegatingEngine(array(new PhpEngine(new TemplateNameParser(), $loader), new CustomEngine()));
     echo "===== Php Engine ===" . PHP_EOL;
     echo $templating->render("hello.php", array("firstname" => "Fabien"));
     echo PHP_EOL;
     echo "===== Custom Engine ====" . PHP_EOL;
     echo PHP_EOL;
     echo $templating->render("hello.html");
     echo PHP_EOL;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = array())
 {
     $this->_logDebug(sprintf('Start render of template <code>%s</code>', $name));
     $toReturn = parent::render($name, $parameters);
     $this->_logDebug(sprintf('Finished rendering template <code>%s</code>', $name));
     return $toReturn;
 }
 /**
  * Detect if the response has media field in her content,
  * and add css, js and templates for mustaches.
  *
  * @param FilterResponseEvent $event
  *
  * @return FilterResponseEvent
  */
 public function addContent(FilterResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         return;
     }
     $response = $event->getResponse();
     $content = $response->getContent();
     if (strpos($content, 'data-apoutchika-media="') !== false) {
         $js = array();
         // Include libs
         $libs = array('jquery', 'jqueryui', 'underscore', 'backbone', 'backbonejjrelational', 'mustache', 'dropzone', 'jcrop');
         foreach ($libs as $lib) {
             if ($this->include[$lib] === true) {
                 $js[] = 'bundles/apoutchikamedia/js/libs/' . $lib . '.js';
             }
         }
         // Include apps
         $apps = array('init', 'models', 'collections', 'viewAdd', 'viewEditor', 'viewField', 'viewList', 'router', 'app');
         foreach ($apps as $app) {
             $js[] = 'bundles/apoutchikamedia/js/' . $app . '.js';
         }
         $content_js = '';
         foreach ($js as $n) {
             $content_js .= '<script src="';
             $content_js .= $this->assetsHelper->getUrl($n);
             $content_js .= '" type="text/javascript"></script>';
         }
         $css = array();
         $css[] = $this->css !== null ? $this->css : 'bundles/apoutchikamedia/css/main.css';
         if ($this->include['jcrop'] === true) {
             $css[] = 'bundles/apoutchikamedia/css/jcrop.css';
         }
         $content_css = '';
         foreach ($css as $n) {
             $content_css .= '<link rel="stylesheet" type="text/css"  href="';
             $content_css .= $this->assetsHelper->getUrl($n);
             $content_css .= '" />';
         }
         $html = $this->templating->render('ApoutchikaMediaBundle:Media:media.html.twig');
         $content = preg_replace('#</head>#', $content_css . '</head>', $content);
         $content = preg_replace('#</body>#', $html . $content_js . '</body>', $content);
         $response->setContent($content);
         $event->setResponse($response);
     }
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage No engine is able to work with the template "template.php"
  */
 public function testGetInvalidEngine()
 {
     $firstEngine = $this->getEngineMock('template.php', false);
     $secondEngine = $this->getEngineMock('template.php', false);
     $delegatingEngine = new DelegatingEngine(array($firstEngine, $secondEngine));
     $delegatingEngine->getEngine('template.php', array('foo' => 'bar'));
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function getEngine($name)
 {
     $this->resolveEngines();
     return parent::getEngine($name);
 }
示例#6
0
 /**
  * Returns a rendered template as a string
  *
  * @param String $template
  * @param Array $params
  * @return String
  * @author Dan Cox
  */
 public function render($template, $params = array())
 {
     return $this->delegator->render($template, $params);
 }