We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Volt base layout change not updating cache

I have a main 'layouts/base.volt' template that each of my other templates extend (ie controller/index.volt). When I make a change to base.volt, the cached file in app/cache does not update. But, when I make a change to one of my controller/index.volt files that extend the layouts/base.volt, everything in the cache directory get updated. I used the phalcon dev tools to create my project

/**

  • Setting up the view component */ $di->setShared('view', function () use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

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

        $volt = new VoltEngine($view, $di);
    
        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'
        ));
    
        return $volt;
    },
    '.phtml' => 'Phalcon\Mvc\View\Engine\Php'

    ));

    return $view; });

Any ideas why that would be?



77.7k
Accepted
answer

By default, and for performance reasons, Volt only checks for changes in the children templates to know when to re-compile to plain PHP again, so it is recommended initialize Volt with the option ‘compileAlways’ => true. Thus, the templates are compiled always taking into account changes in the parent templates.

https://docs.phalcon.io/en/latest/reference/volt.html#multiple-inheritance

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

Thank you very much! Right on the money :)