1

我有以下内容:

本地.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>

1列.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

如何让屏幕截图中列出的“子块”实际上是第一个子块?

4

1 回答 1

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>
于 2013-03-05T22:34:28.473 回答