| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
How to override a .twig file from another module? | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
How to override a .twig file from another module?
So I have successfully overridden a number of different core .twig files, but there is one I want to override but another module that I'm using also overrides the same file. The module's modification seems to be used over my own (according to Webmaster Mode).
The skin file I can't override is: skins/customer/modules/QSL/VariantsTableView/skin/customer/product/details/stock/body.twig I tried to create the same file in my module but it isn't being used: skins/customer/modules/KB/TDT/skin/customer/product/details/stock/body.twig
__________________
X-Cart 5.3.2.11 |
|||||||
#2
|
|||||||||
|
|||||||||
Re: How to override a .twig file from another module?
How do you override the template? Through the Webmaster mode?
Please add your X-Cart version to your forum signature.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#3
|
|||||||
|
|||||||
Re: How to override a .twig file from another module?
OK, I updated my signature. I am trying to override the template by adding it to my own custom module (author "KB" name "TDT"). This has worked for lots of other files, for example I have both of these files in my module (in the skins/customer/modules/KB/TDT directory):
skin/customer/product/details/parts/common.extras.twig skin/customer/product/details/parts/common.product-title.twig And these work fine; they replace the core files in the skins/customer/product/details/parts directory. But this file is ignored: skins/customer/modules/KB/TDT/skin/customer/product/details/stock/body.twig Presumably because another module that I'm using also overrides it: skins/customer/modules/QSL/VariantsTableView/skin/customer/product/details/stock/body.twig
__________________
X-Cart 5.3.2.11 |
|||||||
#4
|
|||||||||
|
|||||||||
Re: How to override a .twig file from another module?
How do you override the files? Do you decorate getDefaultTemplate() method and replace the path with a path to your custom file? Or do you use the skin file substitution?
My guess is that renaming your namespace from KB to something that goes after QSL alphabetically (so XC5 loads your module after VariantsTableView) should help. If you use getDefaultTemplate(), @Decorator\After directive may help too.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#5
|
|||||||
|
|||||||
Re: How to override a .twig file from another module?
Quote:
So for the other files I override, I don't have any code at all in any class files to override them. I just put the file in my skin directory and it overrides. I guess I'm not clear on how to use getDefaultTemplate() to help out here. Likewise, looking in the VariantsTableView module, it doesn't have any references to this file in its classes code either. It just has the file there and it overrides the default file. I'd love an example of how I can create a class that will override this .twig file (skins/customer/modules/QSL/VariantsTableView/ski n/customer/product/details/stock/body.twig) which already overrides skins/customer/product/details/stock/body.twig.
__________________
X-Cart Business 5.3.6.8 |
|||||||
#6
|
|||||||||
|
|||||||||
Re: How to override a .twig file from another module?
"QSL/VariantsTableView" goes alphabetically after "KB/TDT", so even if you override the customer/product/details/stock/body.twig file from your "KB/TDT" module's "skin" directory, that module will replace it with its own template file after you.
You can either name your module differently (for example, "X/TBT") so that it goes after "QSL/VariantsTableView", or can do the following trick: 1. You don't register your "skin" directory from your module's Main.php and keep it as simple as possible: PHP Code:
2. You "hack" into the QSL\VariantsTableView module and make its getSkins() method register your "skin" directory: PHP Code:
3. Then you place your templates into skins/customer/modules/KB/TDT/skin/customer/... --- Another way is decorating individual widget classes. For example, skins/customer/modules/QSL/VariantsTableView/skin/customer/product/details/stock/body.twig file overrides the base skins/customer/product/details/stock/body.twig template file. If you search for classes that link to this file, you will find that it is \XLite\View\Product\Details\Customer\Stock class that is doing it (see its getDefaultTemplate() method). So, you: a) create a custom module (without the getSkins() method unless you need the custom "skins" directory to replace other templates) b) put your template into customer/modules/KB/TDT/product/details/stock/body.twig c) decorate ("hack into") the base widget class as follows: PHP Code:
"implements \XLite\Base\IDecorator" is the part that makes classes in your module behave like hacks into existing classes of the X-Cart core or other modules.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions Last edited by qualiteam : 08-31-2017 at 09:25 PM. |
|||||||||
#7
|
|||||||
|
|||||||
Re: How to override a .twig file from another module?
Option #3 was exactly what I needed, thank you so much! I do need other skin files, so I left that in place. And I had already created a subclass of Stock so it was trivial to implement. Thanks again!
__________________
X-Cart Business 5.3.6.8 |
|||||||
|
|||
X-Cart forums © 2001-2020
|