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.

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?



42.3k
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.phalconphp.com/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 :)