Determine if on product page programmatically in Magento

Posted by dfondente on Stack Overflow See other posts from Stack Overflow or by dfondente
Published on 2010-06-14T23:00:00Z Indexed on 2010/06/14 23:02 UTC
Read the original article Hit count: 271

Filed under:
|

I want to insert tracking codes on all of the pages of a Magento site, and need to use a different syntax if the page is a CMS page, a category browsing page, or a product view page. I have a custom module set up with a block that inserts a generic tracking code on each page for now. From within the block, how can I distinguish between CMS pages, category pages, and product pages?

I started with:

Mage::app()->getRequest();

I can see that

Mage::app()->getRequest()->getParam('id');

returns the product or category ID on product and category pages, but doesn't distinguish between those page types.

Mage::app()->getRequest()->getRouteName();

return "cms" for CMS pages, but returns "catalog" for both category browsing and product view pages, so I can't use that to tell category and product pages apart.

Is there some indicator in the request I can use safely? Or is there a better way to accomplish my goal of different tracking codes for different page types?

© Stack Overflow or respective owner

Related posts about php

Related posts about magento