View Full Version : [Template System] Multiple main_page files: Different layout for index page from other pages

06-25-2011, 02:06 AM
There are a number of forum topics that refer to how to establish multiple layouts. The main reference is in the sticky BTS template topic (http://www.oscmax.com/forums/oscmax-v2-features-discussion/14626-bts-template-tutorial-examples-converting-oscommerce-template-bts.html).

I have approached it slightly differently and using the latest BTS with HTML tag format for the template.

Why? If I followed the suggested approach I end up modifying the core file setting for calling main_page and this will break the template switching options for the site.

I've documented this in detail in my blog (http://howden.net.au/thowden/2011/06/oscmax-an-option-for-having-different-main_page-templates/) but here is a summary.

Instead of modifying /index.php to point to a new or alternate main_page.tpl.php like main2_page.tpl.php, this method leaves it alone.

Modify configure_bts.php as suggested. Noting that I call the alternate page main_index_page.tpl.php in order to be clear on its purpose (main2 is a bit obtuse).

In the main_page.tpl.php modify it to establish if there is an alternative file to use.
Change lines 14 and 15 and then insert before line 14 the new if file_exists construct:

require(DIR_WS_INCLUDES . 'meta_tags.php');
//require(DIR_WS_INCLUDES . 'counter.php');

// if there is an alternate file and if this is called from index.php
if ((file_exists('main_index_page.code.php')) || (substr($_SERVER['PHP_SELF'], -9) == 'index.php')) {

$php_template = 'main_index_page.code.php';
$html_template = 'main_index_page.html';
} else {
$php_template = 'main_page.code.php';
$html_template = 'main_page.html';

$bts_php_array = bts_read_php($php_template);
$bts_html_array = bts_read_html($bts_php_array, $html_template);

The two functions also need to be modified on lines 41 & 60 to remove the fixed file name for the parameter.

function bts_read_php($php_template) {


function bts_read_html($php_code_array, $html_template) {

The last bit is to copy main_page.html and main_page.code.php to main_index_page.html and main_index_page.code.php respectively. Noting that a separate main_index_page.tpl.php is not required as we use the main_page.tpl.php as a common launcher.

The above provides for testing if there is an alternative and using it if the calling page is index.php.

This provides a means of containing the changes more within the template and ensures that the calling pages do not need to be modified.

It also allows the template switching to work when switching between templates that have or dont have alternate main_page templates.

Hope I got the code correct here, it is working fine for my test site.