Post by neosdesign » Fri Aug 09, 2013 1:28 am

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.

New member

Posts

Joined
Tue Aug 17, 2010 5:44 pm

Post by butte » Fri Aug 09, 2013 2:32 am

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.

Guru Member

Posts

Joined
Wed Mar 20, 2013 6:58 am

Post by neosdesign » Fri Aug 09, 2013 3:58 am

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.

New member

Posts

Joined
Tue Aug 17, 2010 5:44 pm

Post by neosdesign » Mon Aug 12, 2013 9:06 pm

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!

New member

Posts

Joined
Tue Aug 17, 2010 5:44 pm

Post by butte » Sun Aug 18, 2013 11:58 am

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.

Guru Member

Posts

Joined
Wed Mar 20, 2013 6:58 am
Who is online

Users browsing this forum: No registered users and 18 guests