Disable template caching for development in OpenCart 3

Viewed 27077

I am making changes in my theme templates in OpenCart 3. Due to template caching I have to clear cache every time under "storage/cache" directory. It is very annoying when working and previewing changes frequently during development. Please provide some solution how we can configure caching according to production and development environment.

Note: I have already searched for solutions online but there is no solution related to template caching. Solutions are available to disable image caching but "Image Caching" and "Template Caching" are different features provided in Opencart.

8 Answers

Another way to do this: Open to system\library\template\Twig\Cache\Filesystem.php, find following lines of code

public function load($key)
{
    if (file_exists($key)) {
        @include_once $key;
    }
}

Comment out as in the following code:

public function load($key)
{
    // if (file_exists($key)) {
    //      @include_once $key;
    // }
}

This will remove the template cache of the twig and recreate every time, once development is over you have to remove the comment.

Opencart Version 3.0.2.0 I was having same problem, try working in theme editor or the actual raw twig file, after an hour or two i tried this it worked.

Delete the changes in theme editor and got back editing actual twig file my screen shot

Scott's answer is best but in case it's not available due to version or you want to disable it programmatically you can do this anywhere before the twig is rendered:

$this->config->set('template_cache', false);

in OC 3.0.3.6, if you have some twig extension, like twig managers, after changes maded you should select that extention in modifications and refresh push button on top right corner.

P.S. loose whole day to find this, hope it helps someone

This is similar to Scott's answer but just on the database/backend. In case you can't rely on the UI and can only access the DB (like me, I'm messing up with the UI) it's on settings table search for 'developer_theme' key and set it to false or 0.

UPDATE `oc_setting` SET `value` = '0' WHERE `oc_setting`.`key` = 'developer_theme';
Related