After stumbling upon the following class while looking at magento source code: Mage_Core_Block_Template_Facade, i have absolutely no idea what this class does.
Obviously i have looked at it and investigated a little bit but it just is not clear to me.
Can anyone explain its purpose in life and when it might be useful to use
Mage_Core_Block_Template_Facade, is actually quite simple to understand. It..
Essentially, this is what makes the Facade Block different from other blocks – the interaction with the registry and comparing a registry key/value with a block instance key/value – all from layout xml.
There is only one example of the block being used in core code…
Looking in catalog.xml and product/view.phtml you will see container1 and container2 blocks – they are both identical, but only one is ever rendered in the final output.
So why are they both there? This will explain how Mage_Core_Block_Template_Facade works.
Core is using the facade block as a method to allow the product options block position within product/view.phtml (not within the layout, but within the template itself) to be configurable from in the admin area. If you look in the design tab whilst editing a product, you should notice the last option: “Display Product Options In” – the two dropdown values correlate each to the container1 and container2 blocks that you can see in catalog.xml and view.phtml. Specifically, looking in product/view.phtml you should see container1 and container2 positioned in different divs.
Layout decides which of these blocks to display based on the value set in “Display Product Options In” using the facade block.
Here is how it works…
Check catalog.xml and you will see:
setDataByKey
This sets an identifier for this block that will be evaluted against the registry object. In the context of the options containers, this value will have to match one of the dropdown values in the admin area mentioned previously.
setDataByKeyFromRegistry
Tells the block “hey, when we need to look at product object in the registry and grab the value of the options_container key/attribute”. Akin to:
Mage::registry('product')->getData('options_container');We would expect this value to be container1 or container2 in this specific example.
ifEquals
Finally, ifEquals is called in conjunction with unsetCallChild to remove the container not selected in the admin area.
using container1 as an example…
this calls the ifEquals method on that block instance, if the return value is 0 then container1 will be unset and not rendered.