Skip to content

Instantly share code, notes, and snippets.

@vdubyna
Created September 30, 2012 10:40
Show Gist options
  • Save vdubyna/3806428 to your computer and use it in GitHub Desktop.
Save vdubyna/3806428 to your computer and use it in GitHub Desktop.
Add block on the fly
<?xml version="1.0"?>
<config>
<modules>
<Myspace_Fpcblock>
<version>0.0.1</version>
</Myspace_Fpcblock>
</modules>
<global>
<blocks>
<myspace_fpcblock>
<class>Myspace_Mymodule_Block</class>
</myspace_fpcblock>
</blocks>
<models>
<myspace_fpcblock>
<class>Myspace_Mymodule_Model</class>
</myspace_fpcblock>
</models>
<events>
<controller_action_layout_render_before_cms_index_index>
<observers>
<add_time_before_content>
<class>Myspace_Fpcblock_Model_Observer</class>
<method>prependTimeBlock</method>
</add_time_before_content>
</observers>
</controller_action_layout_render_before_cms_index_index>
</events>
</global>
</config>
<?php
class Myspace_Fpcblock_Model_Observer
{
public function prependTimeBlock($observer)
{
/** @var $layout Mage_Core_Model_Layout */
$layout = Mage::app()->getLayout();
$block = $layout->createBlock(
'Mage_Core_Block_Text',
'myspace_fpcblock_time',
array('text' => "Generation Time: " . date('H:i:s'))
);
$layout->getBlock('content')->insert($block);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment