Disable template caching for development in OpenCart 3

自闭症网瘾萝莉.ら 提交于 2019-11-26 14:48:23

问题


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.


回答1:


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.




回答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;



回答3:


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




回答4:


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.




回答5:


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.




回答6:


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);


来源:https://stackoverflow.com/questions/45220327/disable-template-caching-for-development-in-opencart-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!