Help
Customer Support | Forums

View

View plugins are basically view template pre-filters and allow to change the source code (not the generated HTML output!) of a particular template file.

Similarly to controller or model plugins, each view plugin is assigned to a particular view template. One template can also have multiple plugins assigned.

The intended use for view plugins is to enable easily-installable template customizations (distributable plugins). If you wish to customize only your own site, it would be easier simply to make the changes in template file directly.

Usage

Creating plugins

Each plugin class must extend the abstract ViewPlugin class. The only method that needs to be implemented is process(), which accepts exactly one variable (string with template code). The process() method would make the neccessary changes to the template code and return the modified code.

Class variables

  • smarty - the instance of Smarty
  • application - application (LiveCart) instance

Class methods

  • process($code) - You'll have to implement this one. Contains all the plugin logic. Must return the modified template code.

Installation

The plugin class file must have the same name as the plugin class. So, if the class name is TestPlugin, the file name would have to be TestPlugin.php

To install a plugin, simply add the plugin class file to /plugin/view/template/file/path/ directory. For example, if you wanted to create a plugin for the /category/productListItem.tpl template, the plugin file would have to be added to the /plugin/view/category/productListItem/ directory. Please note that the plugin directory path names must have exactly the same case as the template directory path names.

Example

Display product manufacturer's name in category product list

We'll add the manufacturer's name in brackets after the product name:


<?php 
    
class ManufacturersName extends ViewPlugin
    
{
        public function 
process($code)
        {
            
// the plugin code will usually consist of str_ or preg_ replaces
            
return str_replace('{$product.name_lang}</a>''{$product.name_lang}</a> ({$product.Manufacturer.name})'$code);
        }
    }
?>

User Contributed Notes

1 comment received. Add your comment.