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?

3
  • what are you planning on doing with it? I dont know about checking a block in an observer but what about core_block_abstract_to_html_after? Commented Nov 10, 2013 at 16:00
  • I have an observer that is going to add some html to a block but i need to know if it was already rendered or not Commented Nov 10, 2013 at 16:07
  • ah ok, is it a core event? if so which one :) Commented Nov 10, 2013 at 16:08

1 Answer 1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.