1

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:

$this->loadLayout()
                   ->getLayout()
                   ->getBlock('root')
                   ->setTemplate('page/1column.phtml');      
$this->renderLayout();
1

3 Answers 3

1

No.

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.

0

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>
</reference>
0

Yes Zou can do That But Before that You have load a new layout handle by adding plugin to Magento\Framework\View\Result\Layout

Please check this Answer You will Get Help if You need clarification i will do it for you please let me know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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