【问题标题】:Magento Template designMagento 模板设计
【发布时间】:2012-06-06 10:13:36
【问题描述】:

在我的 magento 模板中,我在主页中使用了以下代码“getChildHtml('content')”。它在哪里使用模板文件中的 getChildHtml() 加载内容?

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以在 page.xml 中找到您页面的全局结构。例如,如果您可以使用 3 列

    <default translate="label" module="page">
        <label>All Pages</label>
        <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
    ....
    

    然后,在您的设计主题的模板页面/3columns.phtml 中,您可以看到此 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') ?>
            <div class="main-container col3-layout">
                <div class="main">
                    <?php echo $this->getChildHtml('breadcrumbs') ?>
                    <div class="col-wrapper">
                        <div class="col-main">
                            <?php echo $this->getChildHtml('global_messages') ?>
                            <?php echo $this->getChildHtml('content') ?>
                        </div>
                        <div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
                    </div>
                    <div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
                </div>
            </div>
            <?php echo $this->getChildHtml('footer') ?>
            <?php echo $this->getChildHtml('before_body_end') ?>
        </div>
    </div>
    <?php echo $this->getAbsoluteFooter() ?>
    </body>
    </html>
    

    使用 getChildHtml('content') ?>。 这能解决您的问题吗?

    【讨论】:

    • 是的,我的问题已在您的代码的帮助下得到解决。谢谢
    • 我还有一个问题。你能解释一下 Mage::getModel() 和 Mage::getSingleton() 在 magento 集合加载中的区别吗?
    • 这是一种设计模式,在 Magento 中有很多这样的模式。 Whit Mage::getSingleton() 你确定对象 ob 的实例是唯一的,例如:Mage::getSingleton('customer/session')。您想要原始对象,以检索实际活动的会话,使用 Mage::getModel() 您在调用中实例化一个新对象。但是你可以提出一个新问题。我已经准备好回答了:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 2015-12-21
    • 2018-07-03
    • 1970-01-01
    相关资源
    最近更新 更多