Jimbola Posted August 23, 2014 Share Posted August 23, 2014 Hi, In this post Vekia explains how to create an IF statement to display a different product layout based on product ID. http://www.prestashop.com/forums/topic/239320-2-different-product-pages-with-separate-css/ Is it possible to take it further, so instead of an IF statement the product.tpl file consists only of a CASE statement directing to a different file based on the product ID or category ID. Like this SELECT CASE Product Category = 4 then ProductShoes.tpl Product Category = 5 then ProductHats.tpl Product ID = 26 then ProductiPod.tpl ELSE DefaultProduct.tpl END SELECT Possible, if so can anyone help with the code? Thanks Link to comment Share on other sites More sharing options...
vekia Posted August 23, 2014 Share Posted August 23, 2014 you mean that you want to use switch function ? something like: switch ($product->id) { case 1: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-1.tpl'); break; case 2: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-2.tpl'); break; case 3: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-3.tpl'); break; case 4: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-4.tpl'); break; } ? Link to comment Share on other sites More sharing options...
Jimbola Posted August 23, 2014 Author Share Posted August 23, 2014 you mean that you want to use switch function ? something like: switch ($product->id) { case 1: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-1.tpl'); break; case 2: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-2.tpl'); break; case 3: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-3.tpl'); break; case 4: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-4.tpl'); break; } ? Yes that looks like what I mean, is the product.tpl the best place to put this code or is there a better place to put it, higher up in the hierarchy? Link to comment Share on other sites More sharing options...
Jimbola Posted August 24, 2014 Author Share Posted August 24, 2014 you mean that you want to use switch function ? something like: switch ($product->id) { case 1: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-1.tpl'); break; case 2: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-2.tpl'); break; case 3: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-3.tpl'); break; case 4: $this->setTemplate(_PS_THEME_DIR_.'product-for-id-4.tpl'); break; } ? Hi Vekia, I tried this by copy it to a blank product.tpl file, but it doesn't work, the code is simply repeated on the front end? Any ideas where I'm going wrong? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now