在magento之外包括magento标头. $ this-> getChildHtml()的问题 [英] Including magento header outside of magento. Problems with $this->getChildHtml()

查看:58
本文介绍了在magento之外包括magento标头. $ this-> getChildHtml()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对该主题进行了详尽的研究,但找不到答案.

I have researched this topic pretty thoroughly but can't find an answer.

我正在尝试在WordPress页面中包含Magneto头像.我创建了一个新的wordpress模板,并向其中添加了以下代码.

I am trying to include a Magneto head into a WordPress page. I created a new wordpress template and added the following code to it.

try {
    require_once ABSPATH . '/app/Mage.php';

    if (Mage::isInstalled()) {
        $mage = Mage::app();
        Mage::getSingleton('core/session', array('name' => 'frontend'));

        if(Mage::getDesign()->designPackageExists('xxx')) {
            Mage::getDesign()->setPackageName('xxx');
            Mage::getDesign()->setTheme('xxx');             
        }


        // init translator
        $mage->getTranslator()->init('frontend');

        // init head
        $head = $mage->getLayout()->getBlockSingleton('page/html_head');        
} }   

然后在我拥有的模板中稍稍

Then a bit further down in the template I have

echo $head->toHtml();

现在发生的事情是头部的某些部位被回声,而某些部位没有回声.

Now what is happening is some parts of the head are being echoed and some parts are not.

当我进入head.phtml并尝试弄清正在发生什么时,我注意到任何包含

When I go into head.phtml and try to figure out what is happening I notice that any line that contains

$this->getChildHtml()

不会得到回应.

我查看了此示例并注意到作者正在手动添加html和CSS.为什么是这样?为什么不自动添加它们?这是相关问题吗?

I looked at this example and noticed that the author is manually adding the html and CSS. Why is this? Why don't they get added automatically? Is this a related problem

谢谢

推荐答案

要显示在标头块内部生成的块,您需要先创建它,然后将其设置为标头块的子代.

To show a block that is generated inside the header block, you need to first create it, then set it as child of the header block.

例如这是我在Wordpress中显示Magento标头块的方式,其中包括由getChildHtml()在原始标头内生成的货币下拉框.phtml:

eg. Here is how I display within Wordpress a Magento header block, including the currency drop-down block that was generated by getChildHtml() inside the original header.phtml:

Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton("customer/session");
$layout = Mage::getSingleton('core/layout');

$headerBlock = $layout->createBlock('page/html_header')->setTemplate('page/html/header.phtml');
$currencyBlock = $layout->createBlock('directory/currency')->setTemplate('currency/currency.phtml');
$headerBlock->setChild('currency_selector', $currencyBlock);
$headerBlock = $headerBlock->toHtml();

然后,您可以在页面上需要的地方写块:

Then you can write the block where you need it on the page:

echo $headerBlock;

我知道已经有点晚了,但是希望这可以帮助其他人解决这个问题.

I know it's a little late but hopefully this helps others with this issue.

这篇关于在magento之外包括magento标头. $ this-> getChildHtml()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆