layout中的remove和unsetChild方法有什么区别?

Sno*_*ore 21 layout magento

layout中的removeunsetChild方法有什么区别?

例如(在poll.xml布局文件中):

<customer_account_index>
    <reference name="right">
        <action method="unsetChild"><name>catalog_compare_sidebar</name></action>
    </reference>
</customer_account_index>
Run Code Online (Sandbox Code Playgroud)

为什么unsetChild而不仅仅是删除

Dan*_*oof 39

删除节点将在合并所有布局句柄后处理,并且无论哪个布局句柄加载块,都是删除块的好方法; 你只是想完全摆脱一些手柄!它也会递归删除,因此您需要指定的是布局句柄.

另一方面,您可能只想从特定布局句柄中的引用中删除块,在这种情况下,您应该使用unsetChild.它通常用于从引用中删除块,但随后重新插入具有不同位置的相同块.删除时无法做到这一点.

在您的具体示例中,magento开发人员使用它来为magento提供一些灵活性.假设我为帐户索引页面添加了一个子页面,并加载了以下布局句柄:

  • 默认
  • ...
  • customer_account_index
  • customer_account_index_subpage

现在假设在这个子页面上我真的想要'catalog_compare_sidebar'块.如果他们使用'删除',我将无法添加此块(具有此特定名称),因为'remove'将被处理 - 之后 - 我自己添加了块.

这使您可以轻松地从单个文件进行更改; local.xml中.