/** * Renders a template using Haml.php. * * @see View::render() * @throws RuntimeException If Haml lib directory does not exist. * @param string $template The template name specified in Slim::render() * @return string */ public function render($template) { if (!is_dir(self::$hamlDirectory)) { throw new \RuntimeException('Cannot set the HamlPHP lib directory : ' . self::$hamlDirectory . '. Directory does not exist.'); } require_once self::$hamlDirectory . '/HamlPHP/HamlPHP.php'; require_once self::$hamlDirectory . '/HamlPHP/Storage/FileStorage.php'; $parser = new \HamlPHP(new \FileStorage(self::$hamlCacheDirectory)); $file = $parser->parseFile(self::$hamlTemplatesDirectory . $template); return $parser->evaluate($file, $this->data); }
<?php require_once 'lib/HamlPHP/HamlPHP.php'; require_once 'lib/HamlPHP/Storage/FileStorage.php'; // Make sure that a directory _tmp_ exists in your application and it is writable. $parser = new HamlPHP(new FileStorage(dirname(__FILE__) . '/tmp/')); $content = $parser->parseFile('views/index.haml'); echo $parser->evaluate($content, array('foo' => '1'));