We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to automatically "rebuild" template files?

Right now I need to delete my base template and others (the .php file generated by Volt) every time I made some change in my editor.

How can I automate this process via dependency injection or something else, so the rebuilding is done every time on every page reload/refresh in the browser?

I hope there is some solution, because it's nice that is cached in the final app, but during the development I need to see the cahnges straight ahead and not only after I delete the base.phtml.php.

Btw. this is my code in the boostrap file:

 //Setup the view component
    $di->set('view', function(){
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        $view->registerEngines(array(
            ".phtml" => 'Phalcon\Mvc\View\Engine\Volt'
        ));
        return $view;
    });


2.3k
Accepted
answer
edited Mar '14

Take a look at compileAlways option (true\false, i put it into config to have different variants on different environments)

    $view->registerEngines(array(
        '.volt' => function($view, $di) use ($config) {

            $volt = new VoltEngine($view, $di);

            $volt->setOptions(array(
                'compiledPath' => $config->application->cacheVoltDir,
                'compiledSeparator' => '_',
                'compileAlways' => $config->application->alwaysRecompileView
            ));

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ));