cancel
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:

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

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

class Company_Module_Block_Geotarget extends Mage_Core_Block_Template
{
    protected function _toHtml()
    {        
$layout
= Mage::getSingleton('core/layout'); // Generate a CMS block object
$block
= $layout->createBlock('cms/block'); // Set the block ID of the static block
$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.

1 REPLY

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">
        <block_id>homepage-hero</block_id>
    </action>
</block> 
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"