magento 開發 得到block的方法

開發文檔:https://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-4.html

 

1. 在controller部分直接通過createBlock()的方式,直接創建得到$block

public function indexAction()
{
//Get current layout state
$this->loadLayout();
 
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => 'activecodeline/developer.phtml')
);
 
$this->getLayout()->getBlock('content')->append($block);
 
//Release layout stream... lol... sounds fancy
$this->renderLayout();
}

2.然後通過getBlock得到content的block,然後通過append加入上面創建的block即可

3.通過getChild得到子block

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章