On the view.phtml is it possible to write php to change the layout depending on what item is displayed on that page?

Using code similar to this:


You can do this at product level from admin.

  1. Create a custom view.phtml in template/catalog/product/my_view.phtml
  2. Navigate in the admin to Product->Design->Custom Layout Update

Add this block:

<reference name="product.info">
    <action method="setTemplate"><template>catalog/product/my_view.phtml</template></action>


Templates belong to blocks, blocks belong to layouts and are loaded and generated by them. Therefore you can't change the layout from inside itself.

You can/should only change layout templates from a controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.