/** * Compile firewall code * * @package las * @version 1.0 * * @param string $code input firewall code * @param mixed $name name to save file * @param boolean $eval if true parse php code */ public static function compile($code, $name = null, $eval = false) { $compiler = new \Phalcon\Mvc\View\Engine\Volt\Compiler(); $compiler->addExtension(new \Las\Extension\VoltStaticFunctions()); $compiler->addExtension(new \Las\Extension\VoltPHPFunctions()); $php = $compiler->compileString($code); if ($name) { $dir = ROOT_PATH . '/app/common/cache/volt/app/cli/views/'; if (!is_dir($dir)) { $old = umask(0); mkdir($dir, 0777, true); umask($old); } file_put_contents($dir . $name . '.phtml', $php); } return $eval ? eval('; ?>' . $php) : $php; }
<?php $compiler = new \Phalcon\Mvc\View\Engine\Volt\Compiler(); $compiler->compile('views/partials/header.volt'); require $compiler->getCompiledTemplatePath();
public function testVoltCompilerImportRecursiveFile() { @unlink('unit-tests/views/partials/header3.volt.php'); @unlink('unit-tests/views/partials/header2.volt.php'); @unlink('unit-tests/views/test10/import2.volt.php'); $view = new Phalcon\Mvc\View(); $view->setViewsDir('unit-tests/views/'); $volt = new \Phalcon\Mvc\View\Engine\Volt\Compiler($view); //extends $volt->compileFile('unit-tests/views/test10/import2.volt', 'unit-tests/views/test10/import2.volt.php'); $compilation = file_get_contents('unit-tests/views/test10/import2.volt.php'); $this->assertEquals($compilation, '<div class="header"><h1>This is the title</h1></div>'); }
<?php //Create a compiler $compiler = new \Phalcon\Mvc\View\Engine\Volt\Compiler(); //Optionally add some options $compiler->setOptions(array()); //Compile a template string returning PHP code echo $compiler->compileString('{{ "hello" }}'); //Compile a template in a file specifying the destination file $compiler->compileFile('layouts/main.volt', 'cache/layouts/main.volt.php'); //Compile a template in a file based on the options passed to the compiler $compiler->compile('layouts/main.volt'); //Require the compiled templated (optional) require $compiler->getCompiledPath();