Collin
Collin

Reputation: 11

if else statement in PHP for Magento Site, need to hide on Homepage, checkout and success page

Here's what is currently working with not displaying on the homepage. And displaying on all other pages, need help not displaying on /checkout/cart/ and /onepage/ and onepage/successs.

<?php if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()): ?>
<?php else: ?>

(Div I am trying to display only on pages other than homepage,checkout,success)

<?php endif; ?>

Upvotes: 1

Views: 220

Answers (2)

Dhaval
Dhaval

Reputation: 1436

place below code in your header file.

for home page :

<?php if ($this->getIsHomePage()){echo 'this is home page';}else{echo 'this is not home page';}

now we will take one variable $pageIdentifier for other then home page

<?php $pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();?> /* this identifier value will change as per page.so echo this  variable so you will get page identifier on all pages*/

for cart page :

if($pageIdentifier == 'checkout_cart_index'){echo 'this is cart page';}

for onepage checkout page :

if($pageIdentifier == 'aw_onestepcheckout_index_index'){echo 'this is checkout page';}

for order sucess page :

if($pageIdentifier == 'checkout_onepage_success'){echo 'this is sucess page';}

using this code you can get other pages identity and use as per your need.

Hope this will work.

Upvotes: 0

Rohit Goel
Rohit Goel

Reputation: 3554

Please try this

$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();

if($routeName == 'cms' && $identifier == 'home') {
    echo 'This is Magento Homepage.';
} else {
    echo 'This is not a Magento Homepage.';
}

this should work for home page only .For hide on multiple pages you can create a array of pages and check if route name exist in that

thanks

Upvotes: 1

Related Questions