Difference between revisions of "X-Cart:Dynamic .tpl Patcher"

From X-Cart 4 Classic
Jump to: navigation, search
(Using dinamic .tpl patcher to create a module)
 
m (Using dinamic .tpl patcher to create a module)
Line 1: Line 1:
  
== Using dinamic .tpl patcher to create a module ==
+
== Using the dinamic .tpl patcher to create a module ==
  
You can use smarty prefilters/ output filters to insert the module entry points in the current skin while compilation - which is preferrable - or when the template is displayed.  
+
You can use smarty prefilters/output filters to insert the module entry points in the current skin during compilation - which is preferable - or when the template is displayed.  
  
 
You may find the files here: http://help.x-cart.com/index.php?title=File:Dynamic_tpl_patcher.4.7.x.php
 
You may find the files here: http://help.x-cart.com/index.php?title=File:Dynamic_tpl_patcher.4.7.x.php

Revision as of 12:13, 21 October 2016

Using the dinamic .tpl patcher to create a module

You can use smarty prefilters/output filters to insert the module entry points in the current skin during compilation - which is preferable - or when the template is displayed.

You may find the files here: http://help.x-cart.com/index.php?title=File:Dynamic_tpl_patcher.4.7.x.php or here: http://help.x-cart.com/index.php?title=File:Dynamic_tpl_patcher.4.6.x.php

Examples of using prefilters:

1) adding the following piece of code in init function of func_MODULE_init


  if (AREA_TYPE == 'C') {
       require $xcart_dir . XC_DS . 'modules' . XC_DS . 'Pilibaba' . XC_DS . 'lib' . XC_DS . 'dynamic_tpl_patcher.php';
       modules\Pilibaba\lib\x_tpl_add_callback_patch('customer/main/cart.tpl', 'func_pilibaba_tpl_insertButton', X_TPL_PREFILTER);
       modules\Pilibaba\lib\x_tpl_add_callback_patch('customer/minicart.tpl', 'func_pilibaba_tpl_insertButton', X_TPL_PREFILTER);
       modules\Pilibaba\lib\x_tpl_add_callback_patch('modules/Add_to_cart_popup/product_added.tpl', 'func_pilibaba_tpl_insertButton', X_TPL_PREFILTER);
   } 



2) add the following in func_pilibaba_tpl_insertButton

function func_pilibaba_tpl_insertButton($tpl_name, $tpl_source) {//


Example of using output filter run on certain pages:

if (

   'C' != x_get_area_type()
   && x_check_controller_condition(NULL, array('register', 'user_modify'))

) {

   x_tpl_add_regexp_patch(
       'modules/XAuth/linked_accounts_admin.tpl',

'/(<form [^>]*name="registerform"[^>]*>.+)(.+<\/tr>)/USs', '\1%%\2' ); } x_tpl_add_listener('modules/XAuth/register.tpl', 'before', 'func_xauth_prepare_register'); x_tpl_add_listener('modules/One_Page_Checkout/profile/account_info.tpl', 'before', 'func_xauth_prepare_register'); Using prefilters helps to simplify adding modules insert points, including 3rd-party modules.