Tuesday, May 10, 2011

Magento: Check if current page is homepage?

if($this->getIsHomePage()) {
    echo 'You are in Homepage!';
} else {
    echo 'You are NOT in Homepage!';
}
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!';
}

2 comments:

  1. in what file exactly can i paste the code sir ?

    'coz my problem is,
    I want to detect if Im on the homepage and do certain CSS rules for that. hmmm. can you help me ? :)

    ReplyDelete
  2. Put "/app/design/frontend///template/page/html/header.phtml" file.

    ReplyDelete