【问题标题】:getChildHtml did not get any value or contentgetChildHtml 没有得到任何值或内容
【发布时间】:2014-10-21 03:21:02
【问题描述】:

我刚刚学会了如何使用 Magento,从制作新主题开始。我创建了 page.xml、footer.phtml、header.phtml、2columns-left.phtml、head.phtml。问题是模板页面中的getChildHtml 没有得到任何内容。有谁知道我错在哪里?

这就是我得到的

page.xml

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

<layout version="0.1.0">
<default translate="label" module="page">
    <label>All Pages</label>
    <block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml"/>
    <block type="page/html_head" name="head" as="head">
        <action method="addCss"><stylesheet>css/css.css</stylesheet></action>
    </block>
    <block type="core/text_list" name="after_body_start" as="after_body_start" translate="label">
            <label>Page Top</label>
        </block>

        <block type="page/html_header" name="header" as="header">
            <block type="core/template" name="top.search" as="topSearch"/>
        </block>

        <label>Page Header</label>
        <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
            <label>Navigation Bar</label>
            <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
        </block>
        <block type="core/text_list" name="content" as="content" translate="label">
        <label>Main Content Area</label>

            <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>

              <block type="core/text_list" name="left" as="left" translate="label">
                <label>Left Column</label>
            </block>

            <block type="core/messages" name="global_messages" as="global_messages"/>
            <block type="core/messages" name="messages" as="messages"/>

            <block type="core/text_list" name="right" as="right" translate="label">
                <label>Right Column</label>
            </block> 
        </block>
        <block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"></block>

</default>

2columns-left.phtml

<!DOCTYPE html>

<!--[if lt IE 7 ]> <html lang="en" id="top" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" id="top" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" id="top" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" id="top" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" id="top" class="no-js"> <!--<![endif]-->

<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div id="web-container">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
    <?php echo $this->getChildHtml('header') ?>
        <div class="content">
            <?php echo $this->getChildHtml('topMenu') ?>
            <?php echo $this->getChildHtml('breadcrumbs') ?>
            <?php // This left_first block will display above the main content on smaller viewports ?>

            <div class="left"><?php echo $this->getChildHtml('left') ?></div>

            <div class="right">
                <?php echo $this->getChildHtml('global_messages') ?>
                <?php echo $this->getChildHtml('right') ?>
            </div>

        </div>
    </div>
    <?php echo $this->getChildHtml('footer_before') ?>
    <?php echo $this->getChildHtml('footer') ?>
    <?php echo $this->getChildHtml('global_cookie_notice') ?>
    <?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>

提前致谢 (•̀ω•́ )σ

【问题讨论】:

    标签: php magento


    【解决方案1】:

    getChildHtml() 是一种从您的布局文件(.xml) 中分配的.phtml 文件加载内容的方法。 page.xml 文件中的每一件事都很好,除了一件事,你需要添加这个,

    <page_two_columns_right translate="label">
            <label>All Two-Column Layout Pages (Right Column)</label>
            <reference name="root">
                <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
                <!-- Mark root page block that template is applied -->
                <action method="setIsHandle"><applied>1</applied></action>
                <action method="setLayoutCode"><name>two_columns_right</name></action>
            </reference>
        </page_two_columns_right> 
    

    布局文件中的&lt;reference&gt; 标记允许您更改目标块,&lt;action&gt; 标记允许您在正在使用的块内运行块方法。如需更多信息,请参阅 here

    上面提到的块是从我的 magento 1.9 复制的。较低版本可能会有所不同。所以请参考你的magento(默认)布局系统,他们是如何使用它的......

    【讨论】:

    • 我试图用默认的 page.xml 替换我的 page.xml,它工作正常。但是当比较它们时,我找不到我错了=[[
    • 使用默认值时工作正常,因此问题仅在您的 page.xml 文件中。比较一下吧。
    • 啊,找到了。根块错误,我给了它一个自我关闭标签:/
    猜你喜欢
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2019-10-23
    • 2012-03-09
    相关资源
    最近更新 更多