Forums / Templates, Stylesheets, Page Layout / Switching templates at run time

Switching templates at run time

Locked

Views: 21,490

Results 21 to 40 of 60
This thread is locked. New replies are disabled.
22 Mar 2007, 3:06 PM
#21
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Switching templates at run time

Sorry for the confusion, kuroi... I'll try changing the flash where its embedded instead of the whole template... Do you know where I should do this? Also, Id like for my subcategories of video to have the same swf as my video category, the software sub-cats to have the same swf as my software cat etc.

John L.
MultiMedia Designer

22 Mar 2007, 4:31 PM
#22
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Switching templates at run time

You would do it where you embedded the flash file.

There are two possible solutions for having the categories and sub categories display the same flash movie. The simplest to implement would be to simply give each case a list of categories in string form upon which to act e.g.> case "1":

case "1_3":
case "1_4":
case "1_5":
<code to embed 1st flash movie>;
break;

case: "2":
case: "2_6":
case: "2_7":
<code to embed 2nd flash movie>;
break;

etc.But this is crude and a pain to maintain, so better would be to right a small PHP string function to return anything before an underscore, and call it to get the top level category and throw away the rest of the $_GET['cPath'].

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

22 Mar 2007, 4:59 PM
#23
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

kuroi,

i dont have very much experience with PHP so dont laugh too hard when ya see this. i believe my flash is embedded in my tpl_header. heres what i have in my tpl_header:

<?php 

case: "1":
echo get_flashed('header','820','113'); 
break;

case: "2":
case: "2_6":
echo get_flashed('header_video','820','113');
break;

?>

and im getting the following error:

Parse error: parse error, unexpected T_CASE in /home/content/s/t/u/studiostyles/html/TEST/includes/templates/jlawless/common/tpl_header.php on line 89

Not sure where i went wrong there... any help outta this mess would be appreciated.

John L.
MultiMedia Designer

22 Mar 2007, 5:26 PM
#24
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

OK! Ive got the "crude" version working and I can see why it would be crude because i would have to keep repeating these cases for all of my categories plus id have to remember to do this every time i needed to upload

 if($_GET['cPath']) {
    switch($_GET['cPath']) {
case 1: //sports
echo get_flashed('header','820','113');
break;
case 2: //event holiday
echo get_flashed('header','820','113');
break;
case 6: //video
echo get_flashed('header_video','820','113'); 
break;
  }
 }

how would i go about doing this?

But this is crude and a pain to maintain, so better would be to right a small PHP string function to return anything before an underscore, and call it to get the top level category and throw away the rest of the $_GET['cPath'].

John L.
MultiMedia Designer

22 Mar 2007, 5:46 PM
#25
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

ALSO, when I add a product to the category... i get the following error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/t/u/studiostyles/html/TEST/includes/application_top.php:263) in /home/content/s/t/u/studiostyles/html/TEST/includes/functions/functions_general.php on line 81

anyone know what that might be about?

John L.
MultiMedia Designer

22 Mar 2007, 5:53 PM
#26
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Switching templates at run time

In a clean install of the current version of Zen Cart, the line referenced by your error is in the middle of a comment block so couldn't have caused the problem.

I rather assume therefore assume that you are either using an older version, or have modded the current version with something that has replaced the default functions_general file. Could you provide more background?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

22 Mar 2007, 6:04 PM
#27
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

Im using zc version 1.3.5. i am also using the nnez_flo mod for my flash. does this mean i need to upgrade or can i just modify the functions_general.php?

John L.
MultiMedia Designer

22 Mar 2007, 6:15 PM
#28
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

here is the code found around that line in the functions_general.php:

// clean up URL before executing it

  while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);

  while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);

  // header locates should not have the & in the address it breaks things

  while (strstr($url, '&')) $url = str_replace('&', '&', $url);



    header('Location: ' . $url);



    zen_exit();

  }

John L.
MultiMedia Designer

22 Mar 2007, 7:44 PM
#29
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

My flash does not come up at all in my index or any other page that doesnt contain a cPath. Here's my code:

 if(isset($_GET['cPath'])) {
    switch((int)$_GET['cPath']) {
case 6: //video - change out case numbers with category id numbers
echo get_flashed('header_video','820','113'); 
break;
case 7: //software - change out case numbers with category id numbers
echo get_flashed('header_software','820','113'); 
break;
default: //default
echo get_flashed('header_templates','820','113');
break;
  }
 }

John L.
MultiMedia Designer

22 Mar 2007, 7:53 PM
#30
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

SOLUTION:

i fixed the last problem with the following:

<?php
   
 if(isset($_GET['cPath'])) {
    switch((int)$_GET['cPath']) {
case 6: //video - change out case numbers with category id numbers
echo get_flashed('header_video','820','113'); 
break;
case 7: //software - change out case numbers with category id numbers
echo get_flashed('header_software','820','113'); 
break;
default: //default
echo get_flashed('header_templates','820','113');
break;
  }
 }
 else echo get_flashed('header_templates','820','113');
?>

seems to work so far....

Still dont know what the prob is with getting the following error when i add a product to my category:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/s/t/u/studiostyles/html/TEST/includes/application_top.php:263) in /home/content/s/t/u/studiostyles/html/TEST/includes/functions/functions_general.php on line 81

John L.
MultiMedia Designer

22 Mar 2007, 8:36 PM
#31
lawbird123 avatar

lawbird123

Zen Follower

Join Date:
Sep 2006
Location:
Jacksonville, FL
Posts:
231
Plugin Contributions:
0

Re: Switching templates at run time

SOLUTION (semi):

I've seen this error message before after ftp-ing files, they would have spaces at the bottom of the them and id have to go in and remove the spaces until the errors went away. These files had no spaces on the bottom. When i was testing, i only had one product in my category. I put a second product in and the problem was solved. Anyone know what might cause this?

John L.
MultiMedia Designer

30 Mar 2007, 4:47 PM
#32
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Switching templates at run time

No, but someone else recently had the same issue of some problem with one product in a category, that went away when a second product was added.

16 Dec 2007, 12:34 AM
#33
rainthebat avatar

rainthebat

Zen Follower

Join Date:
Feb 2007
Posts:
314
Plugin Contributions:
0

Re: Switching templates at run time

This would be a good one to look at again. Anyone have any success getting some code to work for switching templates at run time? I know 'eccentric' had gotten somewhere, but that solution doesn't seem to work for me.

I need a different template for some cPath's which I can not achieve at all using css, no matter what I try.

16 Dec 2007, 11:03 AM
#34
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Switching templates at run time

Sure. You can create your own init_templates.php file to override the default template directory for some of your categories and put it in your includes/init_includes/overrides folder. This is the approach used for the template switcher on the (sorry, site offline) site.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

16 Dec 2007, 5:19 PM
#35
rainthebat avatar

rainthebat

Zen Follower

Join Date:
Feb 2007
Posts:
314
Plugin Contributions:
0

Re: Switching templates at run time

Yes, that template switcher site is quite impressive - a great introductory for people wondering about zen cart, and wanting to try different templates. My personal favorite is future zen, which I took up for my site in April of 2007.

I will dig deep and try to figure out the code to work for the init_templates. I had tried experimenting with the coding that 'eccentric' had come up with at the beginning of this post, but to no avail. Will try again.

17 Dec 2007, 10:25 PM
#36
rainthebat avatar

rainthebat

Zen Follower

Join Date:
Feb 2007
Posts:
314
Plugin Contributions:
0

Re: Switching templates at run time

It seems that this needs a slight code change to work correctly
(at least with my store).
I wanted the functionality to change templates for just one category,
so I could refine the template for category and product display.

So after copying 'eccentric's code from the beginning of this post,
I made a revision that is working correctly for me now.

On line 37 of: includes/init_includes/overrides/init_templates.php make necessary adjustments...

  
if($_GET['cPath']) {
  switch($_GET['cPath']) {
   case $template_dir = "29"; // directory of your custom cPath template (includes/templates/29)
      break;
   case $template_dir = "29_30"; // directory your custom cPath template (includes/templates/29)
      break;
   case $template_dir = "29_31"; // directory your custom cPath template (includes/templates/29)
      break;
   case $template_dir = "29_32"; // directory your custom cPath template (includes/templates/29)
      break;
   case $template_dir = "29_33"; // directory your custom cPath template (includes/templates/29)
   
  default: // If none of the above 
  $template_dir = "future_zen"; // directory name of custom template (includes/templates/custom_template)
      break;
    }
  }

So when a user goes to cPath 29, the program automatically loads the folder in the directory I created under includes/templates/29

This directory should include all the files in my custom template (which is 'future_zen' in my case.
I only copied the important template files that would be used, and didn't bother with the rest i.e. everything in the 'common' folder, everything in the 'images' folder etc.

Next I ran into some error where the templates would be looking for a file in my custom folder on other parts of the site. The only thing is it doesn't automatically
look in you custom folder, so you need to take these and copy them over
to the regular directories. For example I use a drop down menu
and it had a file in
includes/languages/english/extra_definitions/CUSTOM_TEMPLATE/ ,
so I copied it to
includes/languages/english/extra_definitions/
and that got it working.

27 Dec 2007, 9:38 AM
#37
soundworker avatar

soundworker

New Zenner

Join Date:
Jan 2005
Posts:
38
Plugin Contributions:
0

Re: Switching templates at run time

Is it able to change template for certain specific pages?

like shippinginfo. home page. page-2. page-3 and so on.

How to change the code to achieve that?

27 Dec 2007, 10:39 AM
#38
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Switching templates at run time

Yes. You can create your own includes/init_includes/overrides/init_templates.php to override your normal template for any page by adding conditions or switch statements based on $_GET['page']. Though often using Zen Cart's ability to load different stylesheets for different pages is sufficient, and avoids the need for programming.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

27 Dec 2007, 12:19 PM
#39
soundworker avatar

soundworker

New Zenner

Join Date:
Jan 2005
Posts:
38
Plugin Contributions:
0

Re: Switching templates at run time

I know,
The most I want to know how to code to make home page to use its own template.
I mean how to modify the $_GET['page'] code.

I just don't want to show sidebox on home page.

27 Dec 2007, 12:53 PM
#40
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Switching templates at run time

Turning sideboxes off doesn't require a separate template. It can be done by adapting this FAQ Entry.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)