1

Has anyone else encountered this problem?

I cannot modify files of this type: {% include 'mobshop/template/common/icons/wishlist.twig' %}

The file "wishlist.twig" is modified in the log but the changes do not appear live.

Do you have any suggestions?

DarkBee
  • 16,592
  • 6
  • 46
  • 58
JonsonT
  • 31
  • 4
  • Hi, can you provide more details. what is you OCMOD file and what is the contents of the wishlist.twig file. and also check the system/storage/modification folder and provide the contents of that wishlist.twig file as well – Dmitriy Zhuk Nov 13 '21 at 15:10
  • I did a little test https://www.awesomescreenshot.com/video/6003430?key=352fe9cc6cc18a1f1403c47d3278aa36 – JonsonT Nov 13 '21 at 15:41
  • Only these files do not appear live {% include 'path/file.twig' %}, the default files change. – JonsonT Nov 13 '21 at 15:45

1 Answers1

0

Short answer: you can't modify with OCMod twig files that are added via include method inside the twig template.

How twig include works?

include is twig method that allows you to add partials into your theme which is a cool feature. when twig engin runs, it compiles the template by following the link and adding the html part into the final html output string.

How OCMod works?

OCmod is basically a function that takes in the path of the file (in our case the twig template file path) and after parsing the string modifies it and saves to the OCMod cache.

Then, when OpenCart asks for that file, the OCMod engine tries to first return the cached file, and if that is not available, then the original file.

so all files that are wrapped in modification('') method have this support.

The reason why twig include is not supported by OCMod

From the logic above we can see that the OCMod modification method simply never sees the twig partial file path from the Include method. It is jsut beyond its scope.

The modification method sees only a string {% include 'path-to-partial-file' %} and that is it. it never dives into that path and never tries to create a OCMod cache off of that file.

Conclusion.

You should not use "include" in your themes at all. Its just bad practice in OpenCart themes. Although personally I love this feature of Twig, I am also forced to avoid it.

The only way you should add partials in OpenCart is via the Controller ($this->load->controller('...')) attaching it to the $data field and then displaying it in the template.

And if you still MUST have this feature

PHP Twig engine is a powerful tool and you can extend it to your needs. You can still add an extension that can make the include method to work with OCmod, although I have never added that feature.

Here is a twig extension https://github.com/Dreamvention/2_d_twig_manager/blob/master/system/library/template/Twig/Extension/DTwigManager.php that you can use as an example and modify to your needs.

Enjoy!

Dmitriy Zhuk
  • 757
  • 1
  • 6
  • 9