Skip to main content

Assign different product templates to different categories

Using Creative elements with an override file you can create multiple templates to assign to different product categories.

Create the override folder - override/modules/creativeelements

Then create a creativeelements.php file using this content:

<?php
// Different Product page templates on different Category pages
defined('_PS_VERSION_') or die;
class CreativeElementsOverride extends CreativeElements
{
    public function hookDisplayHeader()
    {
        if ($this->context->controller instanceof \ProductController) {
        	$id_category = $this->context->controller->getProduct()->id_category_default;
        	// category ID => template ID
            $map = [
            10 => 14,
            26 => 14,
            27 => 14,
            28 => 14,
            11 => 7,
            12 => 12,
            13 => 13,
            36 => 10,
            37 => 15,
            
        	];

        	if (isset($map[$id_category])) {
        		Configuration::set('CE_PRODUCT', $map[$id_category]);
        	}
        }
        parent::hookDisplayHeader();
    }
}

 Map your product categories to the appropriate template IDs

 

  • Hits: 7