Today I needed to exclude hot products and recently viewed products block from homepage, so I needed to find if the current page is homepage. The first block of code worked on header.phtml template but not in main page template, so I ended up using 2nd option.
If you need to check this on header.phtml template then use this code:
<?php if($this->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } ?>
If you want to check from other pages than do this:
<?php $is_homepage = Mage::getBlockSingleton('page/html_header')->getIsHomePage(); if($is_homepage) { echo "You are on Homepage!"; } else { echo "You are NOT on Homepage!"; } ?>
or,
<?php $routeName = Mage::app()->getRequest()->getRouteName(); $identifier = Mage::getSingleton('cms/page')->getIdentifier(); if($routeName == 'cms' && $identifier == 'home') { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } ?>
GoWebBaby Magento Development posted on - Wednesday 3rd of October 2012 11:23:40 AM
Kushu posted on - Friday 4th of January 2013 09:02:13 AM
Thangadurai posted on - Wednesday 11th of December 2013 07:40:57 AM
tim posted on - Tuesday 11th of November 2014 01:38:13 AM
kirbeenanette posted on - Thursday 8th of December 2016 02:56:22 AM