G'day,
I'm in a situation whereby I need to be able to load a different template, depending on where the visitor is in the site. Example: the visitor is viewing the category "Men's Clothing," - I want the template in '/includes/templates/mens' to be loaded. When a visitor is viewing "Women's Clothing," - I want the template in '/includes/templates/womens' to be loaded.
I have found the line in 'admin/template_select.php' that is responsible for updating/switching the template that is used the site (line 52):
So, theoretically, I should be able to execute this query replacing the template_dir and template_id with whatever template I want to use - based on what category/section of the site the visitor is viewing. To do this all that would be needed is something like a variable stored in $_GET that has the template_dir. Let's say I know the template_id is 1. The query would be something like:Code:$db->Execute("update " . TABLE_TEMPLATE_SELECT . " set template_dir = '" . $_POST['ln'] . "' where template_id = '" . $_GET['tID'] . "'");
This piece of code works if placed anywhere after line 111 of 'includes/application_top.php', which reads:Code:$db->Execute("update " . TABLE_TEMPLATE_SELECT . " set template_dir = '" . $_GET['template'] . "' where template_id = '1'");
But it will not work if placed before that line, I imagine because this line is responsible for running 'autoload_func.php' which in turn initiates all the classes and objects used throughout the site (at least this is my understanding).Code:require('includes/autoload_func.php');
At present, the code works, only it will only load the new template after you have refreshed the page more than once (or viewed 2 pages with the same $_GET['template']). This is because the first time the page is run, it updates the template with the query. The second time the page is run, the template has already been updated so you see the new template.
So, I need someone who has some advanced knowledge of Zen Cart to give me a pointer here. How can I run a query that will switch templates as the page is generated?
Many thanks.



