Check if current page is category, login, registration, checkout page and more – Magento 1.9

Sometimes in theme development, you will need to display a particular block code for a specific page. To display a specific block of code on a particular page, we can run the below code. This code can ease you to fetch the module, controller, and action name in phtml template file. These codes only work on the phtml template file not in static blocks or cms page in the admin panel.


 $request = Mage::app()->getRequest();
 $module = $request->getModuleName();
 $controller = $request->getControllerName();
 $action = $request->getActionName();

 $request = $this->getRequest();  

The code displays all the requests on the page

 $request->getModuleName(); 

The code displays the module name for example ‘catalog’.

 $request->getControllerName(); 

The code displays the controller name for example ‘product’.

 $request->getActionName(); 

The code displays the action name for example ‘view’.

If you go to the catalog.xml, you will find catalog_product_view. The catalog is equal to the module, the product is equal to the controller and the view is equal to the action name. Below example can display a particular block of code on a specific page.


$request = Mage::app()->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();

if($module == 'catalog' && $controller == 'product' && $action == 'view') {
   //Single product page
}

if($module == 'customer' && $controller == 'account' && $action == 'login') {
   //login page
}

if($module == 'checkout' && $controller == 'cart' && $action == 'index') {
   //Shopping Cart page
}

if($module == 'customer' && $controller == 'account' && $action == 'create') {
   //registration page
}

I hope it helped you a lot. Thank you

Related Posts:

Check if current page is category, login, registration, checkout page and more – Magento 1.9

  1. I read this post completely about the difference of hottest and previous technologies, it’s awesome article.