Disable template caching for development in OpenCart 3
Asked Answered
R

8

22

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.

Ribaudo answered 20/7, 2017 at 16:25 Comment(5)
Possible duplicate of Disable image cache in OpenCartGarin
No its not duplicate, Image caching is another thing and it is not panic during development.Ribaudo
Absolutely right. @RajatJainCadaverine
What exact version do you have? I have 3.0.0.0 and I thought template caching was turned off.Maffa
on opencart 3.0.2.0 version, you can disable cachingPeterec
M
47

You might need to upgrade to a more recent version of OpenCart3 - the first one (3.0.0.0) didn't have a way of doing this in the GUI.

More recent versions, such as 3.0.2.0, have a gear on the admin dashboard. Click the gear and you get options to disable caching.

enter image description here

Maffa answered 21/7, 2017 at 14:54 Comment(1)
Some times if changes has been made in controller and view files. Needs to removed from cache folder. Using ftp. As opencart latest version is using all cache outside of working directoryTwana
D
6

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.

Dike answered 10/2, 2019 at 5:20 Comment(3)
This one works fine! Just don't forget to remove comments at the end! Thnx @rupak-nepaliVanscoy
You are life saver :) +1Lupelupee
Just one problem. When I make changes directly in twig file, it didn't display in front'end but my code display in theme editor. And when I hit save from there, then it displays on front-endLupelupee
I
2

You can also do this from CODE directly if you have the access. Go to this file path below via ftp or cPanel:

system\library\template\Twig\Environment.php

Find

$this->debug = (bool) $options['debug'];

Replace:

$this->debug = (bool) true;
Infant answered 1/1, 2018 at 6:20 Comment(0)
F
2

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

Feticide answered 9/2, 2019 at 19:19 Comment(1)
You need to make sure to include this step Randall has mentioned if you have use the editor. Or else all the other options. aka "developer settings cache off" won't matter.Atrophied
E
1

I think you edit the template as the path: Design->Theme Editor before.

Clear all of the date in the oc_theme data table of your database.

Exurbia answered 10/9, 2017 at 16:8 Comment(1)
Upvoted, this was my case, dont know why you get the down vote.Hydrotaxis
B
1

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);
Biysk answered 4/2, 2018 at 7:0 Comment(3)
Thank you. I didn't notice it.Naraka
$this means the line must be inside a class or any of it's inheritance. which class it is supposed to be? or more specific, which file?German
$this->config can be called from any controller, model and most library classes. The for controllers and models the magic method __get() is used to return $this->registry->get('config'). The op is asking about templating here so presumably they are making changes from within a controller somewhere.Biysk
F
0

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

Feverwort answered 19/8, 2020 at 19:9 Comment(0)
C
0

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';
Countenance answered 22/10, 2020 at 11:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.