Monday 7 October 2013

Check If Home Page, CMS Page Or Any Other Page In Magento.

To check for any other cms page just replace ‘home’ in
the if condition to the identifier of the page you want to check.

< ?php
$route = Mage::app()->getRequest()->getRouteName();
$id = Mage::getSingleton('cms/page')->getIdentifier();
if($route == 'cms' && $id == 'home') {
    echo 'Homepage!';
}
?>

The code shown below checks for cart page. Change the if condition for any other page.

< ?php
$request = $this->getRequest();
$module = $request->getModuleName();   
$controller = $request->getControllerName();   
$action = $request->getActionName();   
if($module == 'checkout' && $controller == 'cart' && $action == 'index'):   
    echo "Cart page"
endif;
?>

No comments:

Post a Comment