Skip to content

Affecting the template with the module

beatnbite edited this page Mar 1, 2012 · 10 revisions

Method 1: Replacing a template file displayed by a widget

To replace a template displayed by a widget you can "decorate" the widget class in your module and modify the method that returns path to the widget template file. Although this is the easiest method, you can't use it for replacing template files which add themselves by using the "@ListChild" tag.

Method 2: Modifying the template which is a part of widget/template list

To make a modification more easier there is the widget/template list concept is implemented in LiteCommerce. The point is that each widget-class and each template can declare in its annotation which lists it will be plugged in. Later, while the cache class generation, all the class-files and template-files are scanned, their annotation are decrypted and the information about the template and widget structure are registered into database. Afterward, when the display method of list is called, the widgets and templates included to this list will be shown ordered by their weights. What the list content depends on:

  1. The list children which are registered in database;

  2. The method which returns the widgets/templates of the current list. Its name is getViewListChildren(), it is declared in \XLite\View\AView class and can be overriden;

  3. The template where the list displaying is called. This template can be changed somehow.

To declare a list element use the @ListChild tag. It works for both templates and classes.

Here is the example of declaring the widget-class as the list element:

/**
* Cart widget
*
* @see   ____class_see____
* @since 1.0.0
*
* @ListChild (list="center")
*/
class Cart extends \XLite\View\Dialog
{
...

The example of declaring the widget-class as the list element with the weight 100 (the widget with the lowest weight will be the first item in the list):

/**
* Cart widget
*
* @see   ____class_see____
* @since 1.0.0
*
* @ListChild (list="center", weight="100")
*/
class Cart extends \XLite\View\Dialog
{
...

The example of declaring the widget-class as the list element with the weight 100 only for admin zone:

/**
* Cart widget
*
* @see   ____class_see____
* @since 1.0.0
*
* @ListChild (list="center", weight="100", zone="admin")
*/
class Cart extends \XLite\View\Dialog
{
...

The example of declaring the template as the element of cart.children list with the weight 20:

{**
* Shopping cart buttons panel
*
* @author    Creative Development LLC <[email protected]>
* @copyright Copyright (c) 2011 Creative Development LLC <[email protected]>. All rights reserved
* @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link      http://www.litecommerce.com/
* @since     1.0.0
* @ListChild (list="cart.children", weight="20")
*}
...

If you want to remove a widget/template from a view list (added there by the core or another module), you can do it by defining the static "runBuildCacheHandler()" method in your Main.php file and adding the following code:

/**
 * Decorator runs this method right after rebuilding the classes cache
 *
 * @return void
 */
public static function runBuildCacheHandler()
{
    \XLite\View\AView::removeWidgetFromList('[child]', [template?], '[list]', '[zone]');
}

Where:

  • [template?] - whether we are removing a template file (true) or a widget (false) from a view list
  • [child] - either a path to the template file or a class name of the widget being removed from the view list
  • [list] - is the full name of the view list from which the template/widget is being removed
  • [zone] - the user interface in which the template/widget was displayed (for the storefront it is "\XLite\Model\ViewList::INTERFACE_CUSTOMER")

Method 3: Substitutional skin

Please see the article Creating the skin module

Clone this wiki locally