Forums / Templates, Stylesheets, Page Layout / Template overide/switch for one category

Template overide/switch for one category

Views: 1,046

Results 1 to 8 of 8
9 Sep 2011, 11:39 AM
#1
davx avatar

davx

New Zenner

Join Date:
Nov 2009
Posts:
80
Plugin Contributions:
0

Template overide/switch for one category

Hi Guys,

I am trying to create a different index_product_list.tpl for one category.

The reason for this is I would like to move items/elements around which cannot be achieved through css.

So far I have done this:

I have added a switch into /includes/init_includes/init_template.php

switch($_GET['cPath']) { //test for a matching string 
  case "158": // if current cPath is 158 set the appropriate template
    $template_dir = "video"; // directory name of template (includes/templates/video)
  break;
} 

This works, however every other aspect of the template changes aswell.

So to get this working correctly I would have to go into every individual folder looking for my overide files, create a copy and rename to video. Along with loading the template and resetting the layout boxes.

It seems pointless making duplicate files, is there any more elegant way to change one template for one category?

Kind Regards

Dave

9 Sep 2011, 11:46 AM
#2
davx avatar

davx

New Zenner

Join Date:
Nov 2009
Posts:
80
Plugin Contributions:
0

Re: Template overide/switch for one category

is there some way I could achieve this with a if statement in main_template_vars.php?

9 Sep 2011, 3:38 PM
#3
gjh42 avatar

gjh42

Black Belt

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

Re: Template overide/switch for one category

Yes, it will be possible to just call an alternate version of the file for your category. I'll have to take a look at which file will be the appropriate location for the alternate call.

You might also consider the approach taken by the Column Layout Grid mod, which has code for both the standard "rows" product listing and the "columns" layout, switching to use different parts of the file as appropriate. That keeps all of the modifications in one file. Actually, what you want to do will probably be best served by modifying product_listing.php and tpl_modules_product_listing.php, just as Column Grid does. Download that mod and look at it to see how it works.

9 Sep 2011, 3:49 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Template overide/switch for one category

Depending on what kind of differences you want in the display, you might also want to edit tpl_index_product_list.php... the exact file(s) to be edited depend on how you want to modify the listing.

Do you have a mockup of the desired layout for your special category?

12 Sep 2011, 2:24 PM
#5
plinth avatar

plinth

New Zenner

Join Date:
Sep 2011
Posts:
14
Plugin Contributions:
0

Re: Template overide/switch for one category

gjh42:

Yes, it will be possible to just call an alternate version of the file for your category. I'll have to take a look at which file will be the appropriate location for the alternate call.

Did you locate the file where this change should be made? I'm also looking to create a new layout for certain categories.

12 Sep 2011, 4:07 PM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Template overide/switch for one category

That really depends on what kind of changes you want to make. If you want fundamental reorganization of the product listing page, you would want to add alternate sections with switches in /includes/templates/your_template/templates/tpl_index_product_list.php.
If you want the parts of individual products in the listing to be organized differently, you would want to edit /includes/modules/your_template/product_listing.php and possibly /includes/templates/your_template/templates/tpl_modules_product_listing.php.

/includes/modules/pages/index/main_template_vars.php calls tpl_index_product_list.php, which calls tpl_modules_product_listing.php, which calls product_listing.php at the very top.

The file to modify or create an alternate for will depend on what you want to do.

12 Sep 2011, 5:15 PM
#8
davx avatar

davx

New Zenner

Join Date:
Nov 2009
Posts:
80
Plugin Contributions:
0

Re: Template overide/switch for one category

Gjh42,

Thanks for the reply, I am taking a look at that module now.

Kind Regards