首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getChildHtml没有得到任何价值或内容。

getChildHtml没有得到任何价值或内容。
EN

Stack Overflow用户
提问于 2014-10-21 03:21:02
回答 1查看 1.9K关注 0票数 1

我刚刚学会了如何使用Magento,从创造一个新的主题开始。我创建了page.xml、footer.phtml、header.phtml、2列-左侧的.page.xml、head.phtml。问题是,getChildHtml在tempalte页面中没有获得任何内容。有人知道我哪里错了吗?

这就是我得到的

page.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<!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>

提前谢谢(·̀ω·́)σ)

EN

回答 1

Stack Overflow用户

发布于 2014-10-21 04:14:50

getChildHtml()是一种方法,它将从您的.phtml文件中加载内容,该文件在您的布局文件(.xml)中分配。page.xml文件中的所有内容都很好,除了一件事,您需要添加以下内容,

代码语言:javascript
复制
<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> 

布局文件中的<reference>标记允许您更改目标块,<action>标记允许您在正在使用的块内运行块方法。有关更多信息,请参见here

上面提到的块是从我的Magento1.9中复制的。它可能会变低版本。因此,请参考您的magento(默认)布局系统,他们如何使用..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26478354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档