Hi,
I have a small function to compile volt templates in app/views_compiled directory (I use gettext, I need php template to generate *.pot file). Here is function:
<?php
$view = null;
$volt = new \Phalcon\Mvc\View\Engine\Volt($view);
$compiler = $volt->getCompiler();
$compiler->addFunction('_', '_');
$compiler->addFunction('md5', 'md5');
$compiler->addFunction('format', 'sprintf');
$_path = realpath(__DIR__ . '/../views/');
function compile_directory($source, $destination) {
global $compiler;
if (is_dir($source)) {
@mkdir($destination);
$directory = dir($source);
while ( FALSE !== ( $readdirectory = $directory->read() ) ) {
if ( $readdirectory == '.' || $readdirectory == '..' || $readdirectory == '.DS_Store') {
continue;
}
$PathDir = $source . '/' . $readdirectory;
if (is_dir($PathDir)) {
compile_directory($PathDir, $destination . '/' . $readdirectory);
continue;
}
$compiled = $compiler->compileString(file_get_contents($PathDir));
file_put_contents($destination . '/' . str_replace('.volt', '.volt.php', $readdirectory), $compiled);
}
$directory->close();
} else {
$compiled = $compiler->compileString(file_get_contens($source));
file_put_contents(str_replace('.volt', '.volt.php', $destination), $compiled);
}
}
compile_directory($_path, __DIR__ . '/compiled/');