public function manejandobloquesAction() { $block_1 = new Mage_Core_Block_Text(); $block_1->setText('Original Text'); $block_2 = new Mage_Core_Block_Text(); $block_2->setText('The second sentence.'); $main_block = new Mage_Core_Block_Template(); $main_block->setTemplate('nofrills/manejandobloques.phtml'); $main_block->setChild('the_first', $block_1); $main_block->setChild('the_second', $block_2); $block_1->setText('Wait , I want this text instead .'); echo $main_block->toHtml(); }
/** * @param Mage_Core_Block_Template $parent * @param $items */ protected function _createChildBlocksRecursively($parent, $items) { foreach ($items as $key => $item) { $block = $this->getLayout()->createBlock('manapro_filtertree/item', $parent->getNameInLayout() . '_' . $key, array('item' => $item, 'filter' => $this, 'template' => 'manapro/filtertree/item.phtml', 'show_in_filter' => $this->getShowInFilter())); $parent->setChild($parent->getNameInLayout() . '_' . $key, $block); $this->_createChildBlocksRecursively($block, $item->getItems()); } }
public function testSetGetUnsetChild() { $layout = Mage::app()->getLayout(); $this->_block->setLayout($layout); // regular block $blockOne = new Mage_Core_Block_Template(); $nameOne = uniqid('block.'); $blockOne->setNameInLayout($nameOne); $layout->setBlock($nameOne, $blockOne); $this->_block->setChild('block1', $blockOne); $this->assertSame($blockOne, $this->_block->getChild('block1')); // block factory name $blockTwo = new Mage_Core_Block_Template(); $blockTwo->setLayout($layout); $blockTwo->setChild('block2', $nameOne); $this->assertSame($blockOne, $blockTwo->getChild('block2')); // anonymous block $blockThree = new Mage_Core_Block_Template(); $blockThree->setIsAnonymous(true); $this->_block->setChild('block3', $blockThree); $this->assertSame($blockThree, $this->_block->getChild('block3')); // unset $this->_block->unsetChild('block3'); $this->assertNotSame($blockThree, $this->_block->getChild('block3')); $this->_block->insert($blockOne, '', true, 'block1'); $this->assertContains($nameOne, $this->_block->getSortedChildren()); $this->_block->unsetChild('block1'); $this->assertNotSame($blockOne, $this->_block->getChild('block1')); $this->assertNotContains($nameOne, $this->_block->getSortedChildren()); }