Jump to content

give every category its own template


Recommended Posts

if you want to change only css styles - it is possbile with simple smarty changes + css modification, and it's easy to achieve.

BUT everything depends on what you exactly expect. Only category listing? Or maybe products too? Only css? or maybe also layout change?

Link to comment
Share on other sites

okay

 

in the controllers/front/ProductController.php you've got something like:

 

 $this->context->smarty->assign('errors', $this->errors);
 $this->setTemplate(_PS_THEME_DIR_.'product.tpl');

 

add there simple if condition (you can add as many conditions as you want)

 

if ($this->product->id_category_default==4){
  $this->setTemplate(_PS_THEME_DIR_.'product-layout-4.tpl');
} else {
     $this->setTemplate(_PS_THEME_DIR_.'produc.tpl');
}

 

code above means:

 

if the product default category is 4 - then prestashop will use product-layout-4.tpl file to display product

if default category will be different - then prestashop will use default product.tpl file

 

 

now you can create own layout file (located in your theme/YOUR_THEME/ dir) named product-layout-4.tpl

Link to comment
Share on other sites

you're welcome :)

 

btw. if you want to use MANY templates, it's better to use switch php function:

 

switch ($this->product->id_category_default) {
   case 1:
    $this->setTemplate(_PS_THEME_DIR_.'product-layout-1.tpl');
    break;
   case 2:
    $this->setTemplate(_PS_THEME_DIR_.'product-layout-2.tpl');
    break;
   case 3:
    $this->setTemplate(_PS_THEME_DIR_.'product-layout-3.tpl');
    break;
   default: 
       $this->setTemplate(_PS_THEME_DIR_.'product.tpl');
}

 

it's much better than if conditions, moreover, you can define default value

 

feel free to write if you've got any other questions related to this case

 

regards

Link to comment
Share on other sites

×
×
  • Create New...