Example #1
0
 /**
  * Render a template
  *
  * @param   string  $source   The template path or content
  * @param   array   $data     An associative array of data to be extracted in local template scope
  * @throws \RuntimeException If the template could not be loaded
  * @return string The rendered template
  */
 public function render($source, array $data = array())
 {
     parent::render($source, $data);
     //Let mustache load the template by proxiing through the load() method.
     $result = $this->_mustache->render($source, $data);
     //Render the debug information
     return $this->renderDebug($result);
 }
Example #2
0
 /**
  * Render a template
  *
  * @param   string  $source     The template url or content
  * @param   array   $data       An associative array of data to be extracted in local template scope
  * @return string The rendered template source
  */
 public function render($source, array $data = array())
 {
     parent::render($source, $data);
     //Load the template
     if ($this->getObject('filter.path')->validate($source)) {
         $source_file = $this->locateSource($source);
         if (!($cache_file = $this->isCached($source_file))) {
             $source = $this->loadSource($source_file);
             $source = $this->compileSource($source);
             $cache_file = $this->cacheSource($source_file, $source);
         }
     } else {
         $name = crc32($source);
         $source_file = '';
         if (!($cache_file = $this->isCached($name))) {
             $source = $this->compileSource($source);
             $cache_file = $this->cacheSource($name, $source);
         }
     }
     //Include the template
     $result = (include $cache_file);
     //Render the debug information
     return $this->renderDebug($result);
 }
Example #3
0
 /**
  * Cache the compiled template source
  *
  * Write the template content to a file buffer. If cache is enabled the file will be buffer using cache settings
  * If caching is not enabled the file will be written to the temp path using a buffer://temp stream.
  *
  * @param  string $name     The file name
  * @param  string $source   The template source to cache
  * @throws \RuntimeException If the template cache path is not writable
  * @throws \RuntimeException If template cannot be cached
  * @return string The cached template file path
  */
 public function cacheSource($name, $source)
 {
     if (!($file = parent::cacheSource($name, $source))) {
         static::$__buffer->truncate(0);
         static::$__buffer->write($source);
         $file = static::$__buffer->getPath();
     }
     return $file;
 }
Example #4
0
 /**
  * Unregister a function
  *
  * @param string    $name   The function name
  * @return TemplateEngineTwig
  */
 public function unregisterFunction($name)
 {
     parent::unregisterFunction($name);
     $functions = $this->_twig->getFunctions();
     if (isset($functions[$name])) {
         unset($functions[$name]);
     }
     return $this;
 }