Recently Updated

My Services

Blog: Another Template-Override Method

Jan272014

When you're developing a plugin that needs to make major modifications to an existing Zen Cart template file, it can be difficult and/or cumbersome to add the required conditional statements and keep your code readable.  Zen Cart has a built-in mechanism to help!

The file /includes/templates/{current template}/common/main_template_vars.php (loaded by your store's /index.php) sets the name of the file to be loaded to provide the formatting for the current page (page_name).  That file is either

  1. /includes/modules/pages/page_name/main_template_vars.php, if that file exists.
  2. /includes/templates/{current template}/templates/tpl_page_name_default.php, otherwise.

For example, to create a template override for a major change to the formatting of the account_history_info page for a plugin I've got in the works, I created the file /includes/modules/pages/account_history_info/main_template_vars.php and programmed that file to contain:

$tpl_page_body $is_multiship_order) ? '/tpl_account_history_info_multiship.php' : '/tpl_account_history_info_default.php';
require($template->get_template_dir($tpl_page_body,DIR_WS_TEMPLATE, $current_page_base,'templates'). $tpl_page_body);

That code will load the either my customized template or the built-in, default formatting template, depending on whether or not the order currently being displayed contains multiple ship-to addresses. Now, I can fully separate the formatting required to support the multiple ship-to addresses!

Watch the Zen Cart forums for the availability announcement for the Multiple Ship-To Addresses plugin!

Copyright © 2012-2021 Vinos de Frutas Tropicales. Powered by Zen Cart