gpt4 book ai didi

Magento:如何以编程方式创建子 block ?

转载 作者:行者123 更新时间:2023-12-04 16:24:43 25 4
gpt4 key购买 nike

我有一个页面,其中包含一些以编程方式包含的模板块,如下所示:

public function indexAction() {
$this->loadLayout();
$block = $this->getLayout()
->createBlock('core/template')
->setTemplate('somefolder/sometemplate.phtml');

$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();

}

我想放在 里面sometemplate.phtml , $this->getChildHtml('somechild') 插入另一个块。

我试过了
        $box = $this->getLayout()
->createBlock('page/html')
->setTemplate('somefolder/somechild.phtml');
$block->append($box);

但是没有用。
我该怎么做?

最佳答案

我通过使用 解决了这个问题setChild 方法如下:

$block->setChild('somealias',$childBlock);

所以我可以使用
<?php echo $this->getChildHtml('somealias'); ?>

关于Magento:如何以编程方式创建子 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11907756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com