Page 1 of 1

Different product template based on location (or any field)

Posted: Fri Aug 09, 2013 1:28 am
by neosdesign
I am looking to have different product templates for a couple product types. Feature products will have product.tpl and Accessories will have accessory.tpl.

I know I can designate templates in the controller by using IDs

Code: Select all

//42 is the id of the product 
 if($this->request->get['product_id'] == 42){
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
            } else {
                $this->template = 'default/template/product/customproduct.tpl';
            }
        }
        else{
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
            } else {
                $this->template = 'default/template/product/customproduct.tpl';
            }
        }
But I was wondering if I can use an arbitrary product field instead of the ID. For example, I could enter "accessory" in the location field of a product and that would automatically load the accessory.tpl.

Re: Different product template based on location (or any fie

Posted: Fri Aug 09, 2013 2:32 am
by butte
You can put into play whatever database tables and fields and whatever supportive files you wish. You're essentially on a doable path, you're not threading edge of cliff in dead of night with no lamp, you have some of what to do down, and you can make backups as well as set up an out of the way mirror in order to tinker with it. You can follow among controller, model, language, and template files the actual code in order to conjure the mimics you want. Go for it.

Re: Different product template based on location (or any fie

Posted: Fri Aug 09, 2013 3:58 am
by neosdesign
Thanks for the reply! I guess I was hoping for some help on the syntax of this line:

Code: Select all

if($this->request->get['product_id'] == 42){
How would I change this to check for for the product location field to equal "accessory" for example.

Re: Different product template based on location (or any fie

Posted: Mon Aug 12, 2013 9:06 pm
by neosdesign
Sorry for the bump, but could anyone tell me if there is an 'if' statement I can write that would check the value of an arbitrary product field like location and if there is a match load up an alternate product template?

Thanks!

Re: Different product template based on location (or any fie

Posted: Sun Aug 18, 2013 11:58 am
by butte
Since you know what you're looking for, you can probably sort quickly through the first thing that will happen (big datadump) if you search for "if statement" (that being a good generic catch-all) even with "+ alternate template" or the like (to narrow the catch-all to specifics). The if-else will take care of itself once you zero in on what the conditionals have been used to modify, since this will probably not be the first of its kind in usage, as to products, templates, etc.. A Boolean search would work wonders but we don't have that option.

You could also try stackoverflow that way. There's some seminal stuff over there.