1-If you are in template/page/html/header.phtml template file, then you can check for homepage with the following code:
if($this->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; }
2-If you are elsewhere (in any other .phtml template file or in any other .php class file) then you can use the following code:
if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; }
3-Below is an alternative way to check for homepage:-
$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!'; }
0 Comments