Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

How to override a .twig file from another module?

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 06-03-2017, 01:49 PM
 
kirkbauer2 kirkbauer2 is offline
 

Newbie
  
Join Date: Apr 2017
Posts: 2
 

Default 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
Reply With Quote
  #2  
Old 06-05-2017, 11:01 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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
Reply With Quote
  #3  
Old 06-06-2017, 04:28 AM
 
kirkbauer2 kirkbauer2 is offline
 

Newbie
  
Join Date: Apr 2017
Posts: 2
 

Default 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
Reply With Quote
  #4  
Old 06-13-2017, 05:35 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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
Reply With Quote
  #5  
Old 08-30-2017, 11:34 AM
 
kirkbauer kirkbauer is offline
 

Member
  
Join Date: Dec 2015
Posts: 26
 

Default Re: How to override a .twig file from another module?

Quote:
Originally Posted by qualiteam
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.

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
Reply With Quote
  #6  
Old 08-31-2017, 06:11 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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:
<?php
namespace XLite\Module\KB\TDT;

abstract class 
Main extends \XLite\Module\AModule
{
    public static function 
getAuthorName()
    {
        return 
'A';
    }

    public static function 
getModuleName()
    {
        return 
'Test';
    }

    public static function 
getDescription()
    {
        return 
'Test';
    }

    public static function 
getMajorVersion()
    {
        return 
'5.3';
    }

    public static function 
getMinorVersion()
    {
        return 
'0';
    }

    public static function 
getDependencies()
    {
        return array(
'QSL\VariantsTableView');
    }
}

2. You "hack" into the QSL\VariantsTableView module and make its getSkins() method register your "skin" directory:
PHP Code:
<?php
namespace XLite\Module\KB\TDT;

abstract class 
VariantsTableViewMain extends \XLite\Module\QSL\VariantsTableView\Main implements \XLite\Base\IDecorator
{
    public static function 
getSkins()
    {
        
$skins parent::getSkins();
        
$skins[\XLite::CUSTOMER_INTERFACE][] = 'customer/modules/KB/TDT/skin/customer';
        return 
$skins;
    }
}

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:
<?php
namespace XLite\Module\KB\TDT\View\Product\Details\Customer\Stock;

abstract class 
Stock extends \XLite\View\Product\Details\Customer\Stock implements \XLite\Base\IDecorator
{
    protected function 
getDefaultTemplate()
    {
        return 
'modules/KB/TDT/product/details/stock/body.twig';
    }
}

"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.
Reply With Quote
  #7  
Old 08-31-2017, 06:33 AM
 
kirkbauer kirkbauer is offline
 

Member
  
Join Date: Dec 2015
Posts: 26
 

Default 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
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:24 PM.

   

 
X-Cart forums © 2001-2020