magento直接在controller中创建block and setemplate

1、Loading current Layout

$this->loadLayout();

2、Create a new block  

$block = $this->getLayout->createBlock('block_template_type','test_block_name')->setTemplate(‘customer/test.phtml’);

3、Append the new block to layout

$this->getLayout->getBlock(‘content’)->append($block);//’content‘为$block的父级block的name

4、render the layout

$this->renderLayout()

原文地址:https://www.cnblogs.com/dongtong/p/6124864.html