【问题标题】:Magento XML $this->getChildHtml() necessary?Magento XML $this->getChildHtml() 有必要吗?
【发布时间】:2012-06-09 00:16:15
【问题描述】:

我编辑了以下文件,将时事通讯移动到页脚而不是侧边栏

app/design/frontend/base/default/layout/newsletter.xml

我更改了以下代码:

<reference name="left">
        <block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
    </reference>

到:

<reference name="footer">

为什么我不需要添加

$this->getChildHtml('newsletter')

或类似于footer.phtml? 我不确定何时使用 getChildHtml() 何时不使用。 this article 的练习#2 中的所有步骤都需要吗?
谢谢。

【问题讨论】:

    标签: xml magento php


    【解决方案1】:

    如果你看一下page/html/footer.phtml,它是页脚块的模板

    <div class="footer-container">
        <div class="footer">
            <?php echo $this->getChildHtml() ?>
            <p class="bugs"><?php echo $this->__('Help Us to Keep Magento Healthy') ?> - <a href="http://www.magentocommerce.com/bug-tracking" onclick="this.target='_blank'"><strong><?php echo $this->__('Report All Bugs') ?></strong></a> <?php echo $this->__('(ver. %s)', Mage::getVersion()) ?></p>
            <address><?php echo $this->getCopyright() ?></address>
        </div>
    </div>
    

    你可以看到他们使用下面的PHP来输出子块

    <?php echo $this->getChildHtml() ?>
    

    getChildHtml在没有参数的情况下被调用时,它会输出any被添加的块。这就是为什么您不需要包含自己对$this-&gt;getChildHtml('newsletter')的调用

    【讨论】:

    • 如何使用 local.xml 而不是更改 newsletter.xml 来移动时事通讯?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 2014-06-23
    相关资源
    最近更新 更多