Forums / Templates, Stylesheets, Page Layout / Custom Product Page - for particular product - use separate template

Custom Product Page - for particular product - use separate template

Started by boxes on 29 Nov 2012, 8:08 PM · Views: 1,357

Results 1 to 12 of 12
29 Nov 2012, 8:08 PM
#1
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Custom Product Page - for particular product - use separate template

is it possible to use a separate template for a particular product but all others use default?

such as item-123 uses product template abc123.tpl but all others use standard

thanks

peace

29 Nov 2012, 8:56 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,129
Plugin Contributions:
56

Re: Custom Product Page - for particular product - use separate template

You can *style *the product whose product_id value is 123 differently from all other products by creating a p_123.css file in your custom template's css directory (/includes/templates/YOUR_TEMPLATE/css/p_123.css).

30 Nov 2012, 12:30 PM
#3
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: Custom Product Page - for particular product - use separate template

thanks

thing is, i gotta change the content there too

peace

30 Nov 2012, 2:10 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,129
Plugin Contributions:
56

Re: Custom Product Page - for particular product - use separate template

You could create the file /includes/templates/YOUR_TEMPLATE/product_info/extra_main_template_vars/product_123.php:

<?php
if (((int)$_GET['products_id']) == 123) {
  // Retrieve any special stuff you need from the database
  $tpl_page_body = 'tpl_product_info_display_123.php';  // Use the file /includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display_123.php to format this special product's information
}

You will probably need the p_123.css file, too ...

30 Nov 2012, 3:32 PM
#5
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: Custom Product Page - for particular product - use separate template

lat9:

You could create the file /includes/templates/YOUR_TEMPLATE/product_info/extra_main_template_vars/product_123.php:

<?php if (((int)$_GET['products_id']) == 123) { // Retrieve any special stuff you need from the database $tpl_page_body = 'tpl_product_info_display_123.php'; // Use the file /includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display_123.php to format this special product's information } ``` > You will probably need the p_123.css file, too ... wow, nice! i'd need to exclude the default pricing and other stuff as well cuz this is a customized product that goes beyond the cart capability presently think i could tweak the default template call kinda like this: ``` <?php if (((int)$_GET['products_id']) == 123) { // use special template $tpl_page_body = 'tpl_product_info_display_123.php'; // Use the file /includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display_123.php //to format this special product's information } else { // use normal template { // normal product template code here } }; ```

peace

30 Nov 2012, 6:59 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,129
Plugin Contributions:
56

Re: Custom Product Page - for particular product - use separate template

The normal template (tpl_product_info_display.php) will have already been set into the $tpl_page_body variable by /includes/modules/pages/product_info/main_template_vars.php's processing. All you need to do in your override is to set the name of the template file that will process that special product (and edit the special product's template file to do what you want).

3 Dec 2012, 8:11 PM
#7
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: Custom Product Page - for particular product - use separate template

i think i see the spot, around the following location:

  if ( $res->fields['total'] < 1 ) {

    $tpl_page_body = '/tpl_product_info_noproduct.php';

  } else {

    $tpl_page_body = '/tpl_product_info_display.php';

peace

3 Dec 2012, 9:51 PM
#8
gjh42 avatar

gjh42

Black Belt

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

Re: Custom Product Page - for particular product - use separate template

If you follow lat9's suggestion, you won't need to touch the stock main_template_vars.php at all - always a good thing to avoid editing existing files when you can make a new one that will allow for upgrades without having to maintain/merge stock files.

4 Dec 2012, 12:43 PM
#9
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: Custom Product Page - for particular product - use separate template

gjh42:

If you follow lat9's suggestion, you won't need to touch the stock main_template_vars.php at all - always a good thing to avoid editing existing files when you can make a new one that will allow for upgrades without having to maintain/merge stock files.
All you need to do in your override is to set the name of the template file that will process that special product (and edit the special product's template file to do what you want).

I guess I'm not sure how to do the override

I've figured out some other override stuff but not sure about this one

peace

4 Dec 2012, 12:59 PM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: Custom Product Page - for particular product - use separate template

You could create the file /includes/templates/YOUR_TEMPLATE/product_info/extra_main_template_vars/product_123.php:I haven't used this variant of override directories myself, but I believe if you simply make that file with just the content shown and put it in that folder path, Zen Cart will automatically detect and use it in the appropriate circumstances (product 123's info page).

4 Dec 2012, 6:52 PM
#11
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: Custom Product Page - for particular product - use separate template

thanks, i'll give it a try, will be amazing if it's that easy

thanks again :)

peace

4 Dec 2012, 9:05 PM
#12
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,129
Plugin Contributions:
56

Re: Custom Product Page - for particular product - use separate template

boxes:

thanks, i'll give it a try, will be amazing if it's that easy

thanks again :)
It's that easy (you just need to know where to look :smile:). I've used this form of override on a couple of sites now.