Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a good tutorial on this: <a href="http://magebase.com/magento-tutorials/creating-custom-layout-handles/" rel="nofollow">http://magebase.com/magento-tutorials/creating-custom-layout-handles/</a></p> <p>This uses following event: <strong>controller_action_layout_load_before</strong></p> <p>For this I set up in config.xml following </p> <pre><code>&lt;events&gt; &lt;controller_action_layout_load_before&gt; &lt;observers&gt; &lt;mymodule&gt; &lt;class&gt;mymodule/observer&lt;/class&gt; &lt;method&gt;addAttributeSetHandle&lt;/method&gt; &lt;/mymodule&gt; &lt;/observers&gt; &lt;/controller_action_layout_load_before&gt; &lt;/events&gt; </code></pre> <p>And in Observer.php I will have</p> <pre><code>public function addAttributeSetHandle(Varien_Event_Observer $observer) { $product = Mage::registry('current_product'); /** * Return if it is not product page */ if (!$this-&gt;isBookProduct($product)) { return; } $niceName = 'book'; /* @var $update Mage_Core_Model_Layout_Update */ $update = $observer -&gt;getEvent() -&gt;getLayout() -&gt;getUpdate(); $handles = $update-&gt;getHandles(); // Store all handles in a variable $update-&gt;resetHandles(); // Remove all handles /** * Rearrange layout handles to ensure PRODUCT_&lt;product_id&gt; * handle is added last */ foreach ($handles as $handle) { $update-&gt;addHandle($handle); if ($handle == 'PRODUCT_TYPE_' . $product-&gt;getTypeId()) { $update-&gt;addHandle('PRODUCT_ATTRIBUTE_SET_' . $niceName); } } } protected function isBookProduct($product) { if (null === $product || !($product instanceof Mage_Catalog_Model_Product)) { return false; } // TODO instead of hardcoded value we could use here something neat to get by name thru eav/entity_attribute_set model, some config value which hold that ID or use some other approach... $book_set_id = 9; if ($product-&gt;getAttributeSetId() != $book_set_id) { return false; } return true; } </code></pre> <p>This makes possibility to use in layout xml following:</p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;layout version="0.1.0"&gt; &lt;PRODUCT_ATTRIBUTE_SET_book&gt; &lt;reference name="product.info"&gt; &lt;action method="setTemplate"&gt; &lt;template&gt;mymodule/book/product/view.phtml&lt;/template&gt; &lt;/action&gt; &lt;/reference&gt; &lt;/PRODUCT_ATTRIBUTE_SET_book&gt; &lt;/layout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload