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?

1 Answer 1

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::

5
  • Thanks you as always. I've tried this, but getBlock('page/html_pager') returns false in head. Here is code gist.github.com/anonymous/139e7e76343285f621e5
    – Marvin3
    May 24, 2013 at 14:41
  • Am I missing something?
    – Marvin3
    May 24, 2013 at 14:50
  • Then the block is created later by the product list, maybe. I have no spontanous idea. Maybe tomorrow May 24, 2013 at 22:28
  • updated the answer. May 25, 2013 at 10:27
  • Thank you, I tried that too, now it returns the block but all data in it is null. Probably because it hasn't been initialized yet. It looks like it's impossible to move data from body to head, so I used createBlock instead of getBlock.
    – Marvin3
    May 26, 2013 at 12:39

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.