开发者

Magento <layoutUpdate> vs. <layout>

开发者 https://www.devze.com 2023-04-10 12:30 出处:网络
I have seen in at least one layout xml file the use of the <layoutUpdate> xml node in place of the typical <layout version=\"0.1.0\"> node.I have scoured the interwebs as well as any Magen

I have seen in at least one layout xml file the use of the <layoutUpdate> xml node in place of the typical <layout version="0.1.0"> node. I have scoured the interwebs as well as any Magento Layout books and documents I have but I can't find an explanation about this. I initially thought there was a difference in the order in which it applies the updates, but that d开发者_如何学Pythonoesn't seem to be the case after further testing. Can someone explain what (if any) differences there are between the two?

Thanks!

Example

Typical layout update XML file structure:

<?xml version="1.0"?>
<layout version="0.1.0">
    <some_handle>
        <reference name"some-block">
            ...
        </reference>
    </some_handle>
</layout>

A different version that still seems to work:

<?xml version="1.0"?>
<layoutUpdate>
    <some_handle>
        <reference name"some-block">
            ...
        </reference>
    </some_handle>
</layoutUpdate>

Is there any functional difference between these 2?


The tag is supposed to be <layout />. However, in current versions of Magento (and likely future versions), the name of this tag doesn't matter. Those files are all combined into a single XML tree. The code Magento uses to load those files into a single tree looks like this

$fileStr = file_get_contents($filename);
$fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr);
$fileXml = simplexml_load_string($fileStr, $elementClass);
if (!$fileXml instanceof SimpleXMLElement) {
    continue;
}
$layoutStr .= $fileXml->innerXml();

The last line ($fileXml->innerXml();) is the one we're interested in, . The innerXml method works just like the browser DOM method of the same name. All the child nodes will be extracted into a string, but the root node will be ignored. You could name it <layout />, <layoutUpdate />, <i♥magento />. It currently doesn't matter.

That said, you should name it <layout /> to avoid confusing people.


Module layout update XML files contain the root node <layout />. Any top-level node contained by this root node is a layout update handle. Layout update handles are used to contain sets of layout update XML directives. The version number for the root node is not ever evaluated (to my knowledge).

Layout update handles are essentially arbitrary, and may be any XML-safe string. Depending on how or if the controller action handling the request is using layout updates, certain layout update handles are called into scope.

For more information on the related methods see the following: Mage_Core_Controller_Varien_Action's loadLayout() and renderLayout() methods, Mage_Core_Model_Layout, and Mage_Core_Model_Layout_Update.

0

精彩评论

暂无评论...
验证码 换一张
取 消