/** * Render a template * * @param array $data The data to pass to the template * @throws \RuntimeException If the template could not be rendered * @return string The rendered template source */ public function render(array $data = array()) { parent::render($data); if (!$this->_mustache_template instanceof Mustache_Template) { throw new RuntimeException(sprintf('The template cannot be rendered')); } //Render the template $content = $this->_mustache_template->render($data); //Remove the template from the stack array_pop($this->_stack); return $content; }
/** * 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 cache($name, $source) { if (!($file = parent::cache($name, $source))) { $this->_buffer = $this->getObject('filesystem.stream.factory')->createStream('koowa-buffer://temp', 'w+b'); $this->_buffer->truncate(0); $this->_buffer->write($source); $file = $this->_buffer->getPath(); } return $file; }
/** * Initializes the options for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param KObjectConfig $config An optional ObjectConfig object with configuration options */ protected function _initialize(KObjectConfig $config) { $config->append(array('compiler' => null)); parent::_initialize($config); }
/** * Unregister a function * * @param string $name The function name * @return KTemplateEngineTwig */ public function unregisterFunction($name) { parent::unregisterFunction($name); $functions = $this->_twig->getFunctions(); if (isset($functions[$name])) { unset($functions[$name]); } return $this; }