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

Ric*_*ins 5 magento magento-1.x

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

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

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

}
Run Code Online (Sandbox Code Playgroud)

我想把sometemplate.phtml,$ this-> getChildHtml('somechild')插入到另一个块中.

我试过了

        $box = $this->getLayout()
        ->createBlock('page/html')
        ->setTemplate('somefolder/somechild.phtml');
        $block->append($box);
Run Code Online (Sandbox Code Playgroud)

但没有奏效.我该怎么做?

Ric*_*ins 21

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

$block->setChild('somealias',$childBlock);
Run Code Online (Sandbox Code Playgroud)

所以我可以使用

<?php echo $this->getChildHtml('somealias'); ?>
Run Code Online (Sandbox Code Playgroud)