Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Checking if current page is cart page in template file
 
David Oliver
Sr. Member
 
Avatar
Total Posts:  177
Joined:  2008-04-16
Cologne, Germany
 

How can I check to see if the current page is the cart page from a template file in version 1.4?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

This should work for any version

$request $this->getRequest();
$module $request->getModuleName();
$controller $request->getControllerName();
$action $request->getActionName();
if (
$module == 'checkout' && $controller == 'cart' && $action == 'index'){
//You are in the cart page.
}

[EDIT] typo

 
Magento Community Magento Community
Magento Community
Magento Community
 
Adam Moss
Sr. Member
 
Avatar
Total Posts:  248
Joined:  2009-02-11
Birmingham, UK
 

Probably not as good as the solution above, but I’ve used this before:

<?php $page $_SERVER['REQUEST_URI'];
$onepage "checkout/cart";
$onepagecheck strpos($page$onepage);

if (
$onepagecheck === true{

?>
code in here *
<?php } ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
David Oliver
Sr. Member
 
Avatar
Total Posts:  177
Joined:  2008-04-16
Cologne, Germany
 

Great - thanks.

@tzyganu: I’m now using that in the template.

@Magento Fox: good idea - I’ve done that in non-Magento sites before. Don’t know why I didn’t think of it. smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top