Magento: Use Different Template Files for Specific Products

I encountered the situation this week where there were a few different products that needed to use a slightly modified view.phtml and media.phtml templates. Fortunately, that’s incredibly easy to do.

First, create your new template files. I copied the originals, and created view-rugs.phtml, and media-rugs.phtml in the same directories as the originals. Once that is complete, edit a product, and go to the “Design” tab. In the “Custom Layout Update” text area, you can put the following, which will redefine which templates it uses for that product (I will explain why it works below):

<reference name="">
    <action method="setTemplate"> <template>catalog/product/view-rugs.phtml</template></action>
<reference name="">
    <action method="setTemplate"> <template>catalog/product/view/media-rugs.phtml</template></action>

How does this work? If you were to open up the catalog.xml layout xml file, and scroll down to the “catalog_product_view” section, you’ll see that there are a bunch of templates being loaded up for the product view. Any of these blocks that load up a template can be changed. They all have a name=”something”. If you reference that name (like I did above), you can call the setTemplate action on it to change it to whatever you want it to be.

This entry was posted in Magento. Bookmark the permalink.

8 Responses to Magento: Use Different Template Files for Specific Products

  1. Gavin says:

    Thanks that was helpful!

  2. Pingback: Enabling ImageMagick on Plesk 11 VPS and using it via PHP exec() for Magento configurator images

  3. sandeep says:

    //I am having two category
    //states and natioanl park
    //each category have sub category
    //states having subctegory like,nagpur,mumbai
    //nationalpark subctegory like ashinational park,pench mnational prak
    //when i click on nagpur or mumbai i will get list.phtml
    //i want different template file with for national park so that when user click on nagpur he will get differnet template(list view) and when he click on ashinational park he will get difrent template file(differnt list view)

  4. Inessa says:

    Thanks . Great tips

  5. Is there anything else you have to do because this did not work for me.

  6. Ankit Sharma says:

    It there any way I can put “If condition” to select different product template??

    If product parent category is 20
    then use view.phtml
    else use view-quote.phtml

    Any suggestion would be helpful.