Page 2 of 3
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 1:53 am
by oc2020
Another weird thing I also saw some other user mentioned is, even if I use theme editor to edit and save my twig file, sometimes the change isn't saved when I navigate somewhere else and come back to the same twig file. Any ideas why this thing happens?
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 3:15 pm
by letxobnav
Normally the twig rendering engine compares the dates of the common/header.twig and its processed cache file to see whether it should update the cache with your changes.
I don't think twig compares cache file datetime unless you use set autoreload or debug which both are actually for template development.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 6:08 pm
by straightlight
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 6:28 pm
by letxobnav
I know but that simply deletes the theme cache files, the question was whether twig cache files would expire after a set period or twig checks whether the cache files were stale.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 7:29 pm
by JNeuhoff
Part of the solution would be to use the 'auto_reload', e.g. something like this:
system/library/template/twig.php
Code: Select all
public function render($template, $cache = false) {
// specify where to look for templates
$loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE);
// initialize Twig environment
$config = array('autoescape' => false, 'auto_reload'=>true);
if ($cache) {
$config['cache'] = DIR_CACHE;
}
$this->twig = new \Twig_Environment($loader, $config);
try {
// load template
$template = $this->twig->loadTemplate($template . '.twig');
return $template->render($this->data);
} catch (Exception $e) {
trigger_error('Error: Could not load template ' . $template . '!');
exit();
}
}
catalog/controller/event/theme.php
Code: Select all
public function index(&$route, &$args, &$template) {
$this->log->write("ControllerEventTheme::index: route='$route' priority=1000");
// If there is a template file we render
if ($template) {
// include and register Twig auto-loader
include_once(DIR_SYSTEM . 'library/template/Twig/Autoloader.php');
Twig_Autoloader::register();
// specify where to look for templates
$loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE);
$config = array('autoescape' => false, 'auto_reload'=>true);
if ($this->config->get('template_cache')) {
$config['cache'] = DIR_CACHE;
}
// initialize Twig environment
$twig = new \Twig_Environment($loader, $config);
return $twig->createTemplate($template)->render($args);
}
}
According to
https://symfony.com/doc/current/referen ... uto-reload :
If true, whenever a template is rendered, Symfony checks first if its source code has changed since it was compiled. If it has changed, the template is compiled again automatically.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 8:47 pm
by letxobnav
true but I understand that that is a development setting so I am not sure about the performance impact.
The following options are available:
debug boolean
When set to true, the generated templates have a __toString() method that you can use to display the generated nodes (default to false).
charset string (defaults to utf-8)
The charset used by the templates.
cache string or false
An absolute path where to store the compiled templates, or false to disable caching (which is the default).
auto_reload boolean
When developing with Twig, it’s useful to recompile the template whenever the source code changes. If you don’t provide a value for the auto_reload option, it will be determined automatically based on the debug value.
strict_variables boolean
If set to false, Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist) and replace them with a null value. When set to true, Twig throws an exception instead (default to false).
autoescape string
Sets the default auto-escaping strategy (name, html, js, css, url, html_attr, or a PHP callback that takes the template “filename” and returns the escaping strategy to use – the callback cannot be a function name to avoid collision with built-in escaping strategies); set it to false to disable auto-escaping. The name escaping strategy determines the escaping strategy to use for a template based on the template filename extension (this strategy does not incur any overhead at runtime as auto-escaping is done at compilation time.)
optimizations integer
A flag that indicates which optimizations to apply (default to -1 – all optimizations are enabled; set it to 0 to disable).
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Sun Jun 14, 2020 10:31 pm
by JNeuhoff
There are no observable performance reductions when using 'auto_reload'. In fact, it's finally added in the latest OpenCart master branch.
Having said that, IMHO it was a bad idea to use Twig in the first place, PHP already is a template language anyway.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Mon Jun 15, 2020 7:54 am
by straightlight
JNeuhoff wrote: ↑Sun Jun 14, 2020 10:31 pm
There are no observable performance reductions when using 'auto_reload'. In fact, it's finally added in the latest OpenCart master branch.
Having said that, IMHO it was a bad idea to use Twig in the first place, PHP already is a template language anyway.
Correct. I am correctly in the wonders as to know if it is simply feasible to run a composer update with older versions of the TWIG engine towards a new TWIG engine or should it require modifications to the files mentioned above.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Mon Jun 15, 2020 11:27 am
by oc2020
JNeuhoff wrote: ↑Sun Jun 14, 2020 10:31 pm
There are no observable performance reductions when using 'auto_reload'. In fact, it's finally added in the latest OpenCart master branch.
Having said that, IMHO it was a bad idea to use Twig in the first place, PHP already is a template language anyway.
Hi JNeuhoff, is this safe to use your codes in the previous reply to replace my current ones? I'm a little frustrated about how this twig cache slow down my tests. (I'm using 3.0.3, btw)
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Mon Jun 15, 2020 12:27 pm
by letxobnav
I just change:
to
in system/library/template/twig/environment.php
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Wed Jun 17, 2020 12:02 am
by Melmoth
''auto_reload' => true' didn't work for me. It's weird because no matter the piece of code I change in .twig files it doesn't affect the webpage, but if I delete the same twig files, the webpage actually crashes...

so those are the correct files but the code changes doesn't affect... (I've cleared cache, from directories and from inside the dashborad in OC)
I'm really lost with this, thank you for your ideas
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Wed Jun 17, 2020 12:57 am
by xxvirusxx
Melmoth wrote: ↑Wed Jun 17, 2020 12:02 am
It's weird because no matter the piece of code I change in .twig files it doesn't affect the webpage, but if I delete the same twig files
Edited with what?
When you make changes don't forget first to :
Refresh Ocmod modifcations and clear VQMOD cache if you use then clear Theme cache, SASS cache from Dashboard right top gear.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Wed Jun 17, 2020 4:40 pm
by Melmoth
Thank you for your fast anwser mate.
xxvirusxx wrote: ↑Wed Jun 17, 2020 12:57 am
Edited with what?
Good question because I used to use OC native template editor to make small changes, but since I've got this problem,
OC template editor doesn't load any of the twig files. (Maybe that's a clue for finding a solution) so I edit the files using FTP with Filezilla and my code editors.
xxvirusxx wrote: ↑Wed Jun 17, 2020 12:57 am
When you make changes don't forget first to :
Refresh Ocmod modifcations and clear VQMOD cache if you use then clear Theme cache, SASS cache from Dashboard right top gear.
Yes, I've already tried that but problem persists.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Thu Jun 18, 2020 10:21 pm
by oc2020
letxobnav wrote: ↑Mon Jun 15, 2020 12:27 pm
I just change:
to
in system/library/template/twig/environment.php
This doesn't work for me either. This twig cache issue is the biggest confusion for me so far, and here is what I'm experiencing:
Scenario A:
1. use theme editor to change some twig files from Admin Theme Editor
2. save it
3. clear cache from admin panel
4. check my website and see the changes happens
5. check the same file next day from theme editor and the file goes back to the older one before I changed anything
Scenario B:
1. use an external editor to edit the twig file
2. save it and use FTP to upload
3. clear cache from admin panel
4. check my website and don't see any changes
5. to make this work I have to copy/paste the same code through Theme Editor but then I go back to Scenario A
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Thu Jun 18, 2020 10:32 pm
by letxobnav
scenario A
check the same file next day from theme editor and the file goes back to the older one before I changed anything
Since the theme editor stores the source in the database.
I would say that you or your host is restoring or losing database content at some interval.
Scenario B
to make this work I have to copy/paste the same code through Theme Editor
Since you have a version of the file stored in the database (theme table) which overides the core and any modification file, file changes there will have no effect.
So either use the theme editor (which you should never do as it is crap) or stick to using OCMOD for all changes.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Thu Jun 18, 2020 11:45 pm
by oc2020
letxobnav wrote: ↑Thu Jun 18, 2020 10:32 pm
scenario A
check the same file next day from theme editor and the file goes back to the older one before I changed anything
Since the theme editor stores the source in the database.
I would say that you or your host is restoring or losing database content at some interval.
Scenario B
to make this work I have to copy/paste the same code through Theme Editor
Since you have a version of the file stored in the database (theme table) which overides the core and any modification file, file changes there will have no effect.
So either use the theme editor (which you should never do as it is crap) or stick to using OCMOD for all changes.
this is good to know! thanks for the explanation!
So if I use theme editor to edit a certain file, it doesn't change the .twig file directly but just saves a changed copy in database?
And if I decided to stop using Theme Editor from now on, what I should do to make it work for an external editor/FTP approach (my scenario B)?
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Fri Jun 19, 2020 8:50 am
by letxobnav
And if I decided to stop using Theme Editor from now on, what I should do to make it work for an external editor/FTP approach (my scenario B)?
remove the version from the theme editor.
If you need to keep those changes, save the source and put it in an ocmod or copy it over the core.
In the end, keep your theme table empty.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Fri Jun 19, 2020 7:57 pm
by straightlight
letxobnav wrote: ↑Fri Jun 19, 2020 8:50 am
And if I decided to stop using Theme Editor from now on, what I should do to make it work for an external editor/FTP approach (my scenario B)?
remove the version from the theme editor.
If you need to keep those changes, save the source and put it in an ocmod or
copy it over the core.
In the end, keep your theme table empty.
We don't copy over the core!
Create new event files would be an alternative solution.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Fri Jun 19, 2020 8:14 pm
by letxobnav
We don't copy over the core!
There is no We.
Re: Opencart 3.0.2.0 default theme doesn't show changes
Posted: Fri Jun 19, 2020 9:04 pm
by straightlight
letxobnav wrote: ↑Fri Jun 19, 2020 8:14 pm
We don't copy over the core!
There is no We.
'We' as an indirect term. Regardless, we don't provide solutions to override core files on the forum.