Thread: lists in .tpl
View Single Post
  #4  
Old 08-20-2014, 12:01 AM
  xplorer's Avatar 
xplorer xplorer is offline
 

X-Cart team
  
Join Date: Jul 2004
Posts: 925
 

Default Re: lists in .tpl

Hi!

Think of lists as named placeholders where widgets and templates can insert themselves - this is how modules can insert custom data into existing templates without modifying them.

Let's say you want to see what is actually displayed in the "layout.header" list. You search through all files for list="layout.header.right" string and find several scripts and templates having @ListChild (list="layout.header.right" ...optional extra parameters go there...) directive in them.

Some of the files would be .tpl templates. Some of them would be PHP classes. PHP classes are easy to extend from your custom module, so you can change their behavior without modifying core files.

One of the files would be the \XLite\View\Minicart class (classes/XLite/View/Minicart.php). This is the widget that renders the minicart.

What is a widget: in most cases it is a pair of a PHP class retrieving data and a .tpl template wrapping the data into HTML. Like in Smary, you may use "variables" in your templates. However, in Smary you "push" data to templates from your PHP scripts (with the "assign" function), whilst in X-Cart 5 templates "pull" data by executing methods of the associated widget class. This allows other modules to extend widget classes and customize the way how data is being retrieved without even touching original templates.

Now back to the Minicart widget. If you check the widget class, you'll find this method:
Code:
/** * Check if widget is visible * * @return boolean */ protected function isVisible() { return parent::isVisible() && !$this->isCheckoutLayout(); }

This is the method that X-Cart 5 executes to determine whether the widget should be displayed on the page. So, to hide the minicart forever you should create a custom module that "decorates" the Minicart widget class and overrides the isVisible() method to make it always return "false".

As you see most of the changes (since X-Cart 4) were made with the "easy upgrades" goal in mind: you can customize your website without changing core files. And you don't have to repatch core files every time you upgrade the store to a new XC5 version. There may be changes incompatible with your custom modules, but locating the places and fixing them is much easier than in XC4.

There are other ways to hide the minicart:
- find the template file rendered by the Minicart widget class (usually the path to the template is combined from the getDir() and getDefaultTemplate() methods of the widget class), create a module with a custom skin and let the custom skin replace the minicart template with an empty one
- find the template that inserts the Minicart widget, create a module with a custom skin and let the custom skin replace the "parent" template with a new one that would not insert the widget; in your case this would be removing the <list> tag (but this will remove all widgets in the list, not just the minicart widget) - this is the (1) point in the Tony's message
- create a custom module that postprocesses view lists after widgets inserted themselves into the lists, finds the minicart widget and removes it from the layout.header list - this is the (2) point in the Tony's post

Last edited by xplorer : 08-20-2014 at 12:21 AM.
Reply With Quote