View Single Post
  #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