2

Continuing previous question.

  • I successfully retrieved a URL of the next catalog page from catalog pager block (Mage_Page_Block_Html_Pager).
  • Now I'm trying to add this URL to the head block (e.g. <link rel="next" url="url-to-next-page" />).

-

public function core_block_abstract_to_html_before(Varien_Event_Observer $observer) {

  $block = $observer->getBlock();

  // Check if current block is pager block
  if($block instanceof Mage_Page_Block_Html_Pager) {
    // I'm getting head block
    $head_block = $Mage::app()->getLayout()->getBlock('head');

    // Trying to add  <link rel="next" url="path-to-next-page" /> to head
    // $block->getNextPageUrl() prints correct value
    // But nothing is added to head
    $head_block->addLinkRel( 'next', $block->getNextPageUrl() );
  }

}

Is it possible at least, or I'm doing this in wrong way?

Marvin3
  • 639
  • 4
  • 13
  • 26

1 Answers1

3

I think the problem is, that the Mage_Page_Block_Html_Head is already renderer, when you iterate ober the Mage_Page_Block_Html_Pager.

You can do it the other way around. Check for instanceof Mage_Page_Block_Html_Head get the pager from the layout and get insert the link.

To get the pager-block in the category view, have a look into the catalog.xml:

<block type="page/html_pager" name="product_list_toolbar_pager"/>

So to get the block:

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

And because I just saw it, do you really typed $Mage in your code? And this worked? It should be Mage::

Fabian Blechschmidt
  • 35,388
  • 8
  • 75
  • 182