1

I need to edit the HTML of product and catalog pages, at this moment I'm using: core_block_abstract_to_html_after and then I check if it is a instanceof Mage_Catalog_Block_Product_View or Mage_Catalog_Block_Category_View.
Unfortunately it is called to many times for the same request (at least 3-4 times).

Reading some answers on this site it looks like this is the last event that is fired before serving page is: controller_front_send_response_after, but I'm not able to distinguish between the two blocks...

So my question is if exists an event which is called just one time before the server sends the page, allow me to identify if it is a product or category page and edit the html?

1
  • 1
    I'm sure you already thought about just changing the templates? – Fabian Blechschmidt May 22 '15 at 13:12
0

I won't argue if this is a good idea or not since I don't know your use case, but handle this information with care, most of the time it's not the appropiate solution:

There is an event controller_front_send_response_before where the whole HTML is rendered but not sent yet.

You can access and modify the HTML like this:

$response = $observer->getData('front')->getResponse();
$html = $response->getBody();
// ...
$response->setBody($html);

And to decide if you are on a product or category page, check which controller action has been executed:

$action = $observer->getData('front')->getAction();
switch ($action->getFullActionName()) {
    case 'catalog_product_view':
        // ...
        break;
    case 'catalog_category_view':
        // ...
        break;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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