HamlPHP::evaluate PHP Method

evaluate() public method

public evaluate ( $content, array $contentVariables = [] )
$contentVariables array
    public function evaluate($content, array $contentVariables = array())
    {
        $tempFileName = tempnam("/tmp", "foo");
        $fp = fopen($tempFileName, "w");
        fwrite($fp, $content);
        // @todo: why not use eval()?
        ob_start();
        extract($contentVariables);
        require $tempFileName;
        $result = ob_get_clean();
        fclose($fp);
        unlink($tempFileName);
        return $result;
    }

Usage Example

 /**
  * 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);
 }
All Usage Examples Of HamlPHP::evaluate