2

During an observer is there a way to determine if a block has been rendered or not?

I can grab the block like so:

Mage::app()->getLayout()->getBlock('the_block_layout_name');

But i want to check if it has already been rendered - i..e its toHtml has been called.

Is this possible? if so how and if not are there any other ideas on how to achieve this or something similar?

Marty Wallace
  • 5,631
  • 13
  • 65
  • 90

1 Answers1

2

There is no property in the $block which is set. But as David said, you can hook into core_block_abstract_to_html_after and just do something like:

public function coreBlockAbstractToHtmlAfter(Varien_Event_Observer $observer) {
$block = $observer->getBlock();
$block->setIsRenderer(true);
}

Then you can just check at any time: if($block->getIsRenderer()) if the block was already rendered.

Of course you can do everything else in this event. And you can check inside the observer:

if($block instanceof Mage_WhateverModule_Block_Whatever_Block_You_Want)
Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182