Showing results for 
Search instead for 
Did you mean: 

Calling block from phtml

Calling block from phtml

Inside my 1column.phtml I have this piece of code:

<?php echo $this->getChildHtml('wide'); ?>

Inside my app/design/frontend/enterprise/wk/layout/wk.xml I have:

     <reference name="wide">
          <block type="wk/geotarget" name="geotarget"/>

Inide app/code/local/Company/Module/Block/Geotarget.php I have:

class Company_Module_Block_Geotarget extends Mage_Core_Block_Template
    protected function _toHtml()
= Mage::getSingleton('core/layout'); // Generate a CMS block object
= $layout->createBlock('cms/block'); // Set the block ID of the static block
->setBlockId('homepage-hero'); return parent::_toHtml(); } }

How do I render this static block based on block ID? I need to do some custom logic inside that Block to get some specific or random block and render it.


Re: Calling block from phtml

Hi @dario_inchoo,


What if you change the <block> definition for something like this:


<block type="cms/block" name="geotarget">
    <action method="setBlockId">
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"