0

I am trying to get CMS page identifier with Mage::getSingleton('cms/page')->getIdentifier(); in a footer.phtml but for some reason I am getting no-route on all the pages.

It used to work before but not anymore. My Magento version is 1.9.3.8. Am I missing something here?

I want to get the home page Identifier so I can use if/else statements to show a different message in homepage footer.

Update: I have tried both the solutions provided by @pawan below, apparently they did not work.

16
  • do you want to show message on only home page. Right ?
    – Pawan
    Nov 3, 2018 at 17:11
  • there are two messages. One will be on the home page and other one rest of the pages.
    – Kevin S
    Nov 4, 2018 at 5:54
  • Please see my Answer, if have any issue let me know.
    – Pawan
    Nov 4, 2018 at 6:05
  • did you try my solution ?
    – Pawan
    Nov 4, 2018 at 9:33
  • See my Edit in answer.
    – Pawan
    Nov 4, 2018 at 16:29

2 Answers 2

0

You can use below code:

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

if($routeName == 'cms' && $identifier == 'home') {
    echo 'Message for Home page';
} else {
    echo 'Common message for others';
}

If above code not work, You can alternatively use:

if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
    echo 'Message for Home page';
} else {
    echo 'Common message for others';
}

Answer Source

Update I

Another way to check Home Page by Marius

$action = Mage::app()->getFrontController()->getAction()->getFullActionName();
    if ($action == 'cms_index_index') {
        echo 'Message for Home page';
    }
else {
     echo 'Common message for others';
}

Update II

It can be done using CSS

<div style="display: none;" class="home-msg">Message for Home page</div>
<div class="rest-msg">Common message for others</div>

<style type="text/css">
    .cms-index-index .rest-msg{display: none;}
    .cms-index-index .home-msg{display: block;}
</style>
6
  • Both of the solutions did not work.
    – Kevin S
    Nov 4, 2018 at 16:10
  • could you check home page identifier in admin ?
    – Pawan
    Nov 4, 2018 at 16:22
  • the url key is home
    – Kevin S
    Nov 5, 2018 at 4:22
  • after $action = Mage::app()->getFrontController()->getAction()->getFullActionName(); when I do echo of $action it returns cms_index_noRoute
    – Kevin S
    Nov 5, 2018 at 4:25
  • if you are not able to check home page, it can be done using CSS
    – Pawan
    Nov 5, 2018 at 4:36
0

Please follow below steps and try.

  1. Disable Cache and see if that is working as expected.
  2. If it is working then that should be related to cache.
  3. I suggest keeping different footer template for the homepage. You can achieve this by changing the footer template in homepage using "Layout Update XML".

Hope this helps. Please try.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.