2011-10-05 98 views
21

現在我正在探索的Magento的管理部分的內部和我偶然在這片XML的:「update」元素在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 />標籤嗎?

回答

50

<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;博士:update手柄基本上是「我目前的合併此佈局佈局」。

+1

我怎麼能代替佈局... –

7

此句柄用於將現有佈局句柄合併到當前佈局。 在您的例子<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定義)

+2

如何Magento的知道手柄在main.xml裏面?如果另一個自定義xml文件包含句柄會怎麼樣?這是否也會合並? –

+0

我認爲Magento會合並這兩個句柄。 –

+1

嗯,這是否意味着Magento會搜索句柄的佈局文件夾中的所有xml文件?抱歉,但不完全理解它。 –