Recently we had a project come in where the customer had a bit of code, with some images and text that he wished to display on the main page only of his Zen Cart. Initially, I mistakenly thought that and index override of the tpl_main_page.php would cover it… Not so, this also produced the code section on all product index pages as well as the main page.
In the past I have added code to tpl_index_default.php to accomplish this. This works okay, but you lose a bit of presentation ability by not having it included in tpl_main_page.php. Things just aren’t quite right in this manner, and it’s not correct either…. So
Thinking cap on, and I came up with the following bit of code hack which uses the built in string for the home page call within Zen Cart… less of a hack, no presentation problems and better ability to be edited.
<!–BOF Main Page Hook Include–>
<?php if ($this_is_home_page) include("main_page_include.php"); ?>
<!–EOF Main Page Hook Include–>
Very simply this is calling to a nice and easy PHP include residing the the root of the Zen Cart directory. This include is only displayed on the page Zen Cart is set to display as the home page. So this works for example even if you have your Zen Cart set to display a category (Configuration >> Layout Settings >> Main Page – Opens with Category) as the home page =-)
Since the tpl_main_page.php is in the correct template override directory and the include is not a Zen Cart file, this doesn’t break your Zen Cart, nor present any upgrade issues. Simple, light and effective as you can add whatever you like in the include. I think rightfully so this can be called a customization instead of a hack.
Leave a Reply
You must be logged in to post a comment.