Results 21 to 30 of 60

Threaded View

  1. #1
    Join Date
    Jul 2006
    Posts
    31
    Plugin Contributions
    0

    Switching templates at run time

    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):

    Code:
    $db->Execute("update " . TABLE_TEMPLATE_SELECT . " set template_dir = '" . $_POST['ln'] . "' where template_id = '" . $_GET['tID'] . "'");
    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 = '" . $_GET['template'] . "' where template_id = '1'");
    This piece of code works if placed anywhere after line 111 of 'includes/application_top.php', which reads:

    Code:
    require('includes/autoload_func.php');
    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).

    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.
    Last edited by eccentric; 20 Jul 2006 at 08:16 AM.

 

 

Similar Threads

  1. switching templates
    By RichardH in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 23 Jul 2008, 10:36 PM
  2. Switching php version in WAMP5 causes install to run
    By GreggShort in forum Installing on a Windows Server
    Replies: 2
    Last Post: 27 Jul 2007, 06:06 AM
  3. switching between templates
    By fairview in forum General Questions
    Replies: 4
    Last Post: 9 Apr 2007, 02:44 PM
  4. switching templates
    By onakat in forum Customization from the Admin
    Replies: 6
    Last Post: 3 Apr 2007, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg