“更新”元素在Magento布局XML中做了什么?

时间:2011-10-05 12:11:55

标签: layout magento

现在我正在探索Magento管理部分的内部,我偶然发现了这条XML:

文件:app/design/adminhtml/default/default/layout/catalog.xml,第55行

50            <block type="core/template" template="catalog/wysiwyg/js.phtml"/>
51        </reference>
52    </adminhtml_catalog_product_new>
53    
54    <adminhtml_catalog_product_edit>
55        <update handle="editor"/>
56        <reference name="content">
57            <block type="adminhtml/catalog_product_edit" name="product_edit"></block>
58        </reference>

<update />标记有什么作用?

2 个答案:

答案 0 :(得分:55)

<update>基本上会拉入另一个句柄。

假设你有这个:

<layout>
   <foo>
      <reference name="header">
          <block type="cms/block" name="some_block" as="someBlock">
              <action method="setBlockId"><block_id>some_block</block_id></action>
          </block>
      </reference>
      <reference name="left">
          <block type="cms/block" name="some_totally_different_block" as="someTotallyDifferentBlock">
              <action method="setBlockId"><block_id>some_totally_different_block</block_id></action>
          </block>
      </reference>
   </foo>
   <bar>
      <update handle="foo" /> 
      <reference name="header">
          <block type="cms/block" name="some_other_block" as="someOtherBlock">
              <action method="setBlockId"><block_id>some_other_block</block_id></action>
          </block>
      </reference>
   </bar>
</layout>

bar生成的XML将是:

<layout>
   <bar>
      <reference name="header">
          <!-- Start of part pulled in from foo -->
          <block type="cms/block" name="some_block" as="someBlock">
              <action method="setBlockId"><block_id>some_block</block_id></action>
          </block>
          <!-- End of part pulled in from foo -->
          <block type="cms/block" name="some_other_block" as="someOtherBlock">
              <action method="setBlockId"><block_id>some_other_block</block_id></action>
          </block>
      </reference>
      <!-- Start of part pulled in from foo -->
      <reference name="left">
          <block type="cms/block" name="some_totally_different_block" as="someTotallyDifferentBlock">
              <action method="setBlockId"><block_id>some_totally_different_block</block_id></action>
          </block>
      </reference>
      <!-- End of part pulled in from foo -->
   </bar>
</layout>

tl; dr: update句柄基本上是“将此布局与我当前的布局合并”。

答案 1 :(得分:8)

此句柄用于将现有布局句柄合并到当前布局。 在您的示例<update handle="editor"/>中,将添加<adminhtml_catalog_product_edit>以下内容:

<editor>
            <reference name="head">
                <action method="setCanLoadExtJs"><flag>1</flag></action>
                <action method="addJs"><script>mage/adminhtml/variables.js</script></action>
                <action method="addJs"><script>mage/adminhtml/wysiwyg/widget.js</script></action>
                <action method="addJs"><script>lib/flex.js</script></action>
                <action method="addJs"><script>lib/FABridge.js</script></action>
                <action method="addJs"><script>mage/adminhtml/flexuploader.js</script></action>
                <action method="addJs"><script>mage/adminhtml/browser.js</script></action>
                <action method="addJs"><script>prototype/window.js</script></action>
                <action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
                <action method="addItem"><type>js_css</type><name>prototype/windows/themes/magento.css</name></action>
            </reference>
</editor>

(“编辑”句柄在app/design/adminhtml/default/default/layout/main.xml中定义)