2013-03-05 52 views
1

我有以下幾點:如何在Magento中正確顯示其父項中的子塊?

local.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<layout> 

    <default> 

     <reference name="root"> 
      <block type="core/text_list" name="foo" as="foo" translate="label"> 
       <label>Foo</label> 
      </block> 
     </reference> 

     <reference name="foo"> 
      <block type="core/template" name="fooblock" template="foo.phtml" /> 
     </reference> 

     <reference name="bar"> 
      <block type="core/template" name="barblock" template="bar.phtml" /> 
     </reference> 

     <reference name="foo"> 
      <action method="insert"> 
       <name>barblock</name> 
      </action> 
     </reference> 

    </default> 

</layout> 

foo.phtml

<div> 
<h1 style="background-color:yellow">Hello New Reference!</h1> 
<div><?php echo $this->getChildHtml() ?></div> 
</div> 

bar.phtml

<h1 style="background-color:yellow">Hello New Reference child!</h1> 

1column.phtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>"> 
<head> 
<?php echo $this->getChildHtml('head') ?> 
</head> 
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>> 
<?php echo $this->getChildHtml('after_body_start') ?> 
<div class="wrapper"> 
    <?php echo $this->getChildHtml('global_notices') ?> 
    <div class="page"> 
     <?php echo $this->getChildHtml('header') ?> 
     <?php echo $this->getChildHtml('global_messages') ?> 
     <?php echo $this->getChildHtml('breadcrumbsContainer') ?> 
     <div class="main col1-layout"> 
      <div class="col-main"> 
       <h1>Custom package, Primary theme</h1> 
       <?php echo $this->getChildHtml('content') ?> 
      </div> 
     </div> 
     <?php echo $this->getChildHtml('footer_before') ?> 
     <?php echo $this->getChildHtml('footer') ?> 
     <?php echo $this->getChildHtml('before_body_end') ?> 
    </div> 
</div> 
<?php echo $this->getChildHtml('foo') ?> 
<?php echo $this->getAbsoluteFooter() ?> 
</body> 
</html> 

這顯示爲以下(看截圖的底部附近):

http://i.stack.imgur.com/BC9bf.png

如何獲取屏幕截圖中列出的「子塊」,實際上是第一個子塊?

回答

1

您使用<reference name="bar">但您的佈局中沒有名稱爲「bar」的塊。你想在「fooblock」裏面定義「barblock」:

<?xml version="1.0" encoding="UTF-8"?> 
<layout> 

    <default> 

     <reference name="root"> 
      <block type="core/text_list" name="foo" as="foo" translate="label"> 
       <label>Foo</label> 
      </block> 
     </reference> 

     <reference name="foo"> 
      <block type="core/template" name="fooblock" template="foo.phtml" /> 
     </reference> 

     <reference name="fooblock"> 
      <block type="core/template" name="barblock" template="bar.phtml" /> 
     </reference> 

    </default> 

</layout> 
+0

做出更改後,你建議它工作的很好,謝謝。 Magento佈局終於開始對我有意義了。 – ryanv 2013-03-06 14:14:53

相關問題