0

Strange in magento footer.phtml file. I am adding a below code in footer area to place text according to current page, whether its cms page or any other page but it is not working correctly.

if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
  echo "CMS page";
}
else{
    echo "Not a CMS page";
}

But its not working, while this code is working fine in header.phtml file provide the correct result according to page.

If I click "Flush Magento Cache" button from "Cache Storage Management" section in back-end it will work for fist time but when I change page to product or vice versa its will not works, it provide the same result all time.

Also header.phtml file code work correctly all time.

Please can anyone suggest me on this?

Mohit Kumar Arora
  • 9,951
  • 7
  • 27
  • 55
Abhilesh Sharma
  • 101
  • 1
  • 9

3 Answers3

0

Try this code:

if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
    echo 'You are in Homepage!';
} else {
    echo 'You are NOT in Homepage!';
}
  • I tried this code but it will also give same result always. I need to click "Flush Magento Cache" button from "Cache Storage Management" section in back-end only then It will change result but after that it will again show same result. – Abhilesh Sharma Jun 12 '18 at 07:50
0

Try the below code:

if(Mage::app()->getRequest()->getRouteName() == 'cms')
{
  echo "CMS page";
}
else{
    echo "Not a CMS page";
}

instead of

if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
  echo "CMS page";
}
else{
    echo "Not a CMS page";
}

Hope this help!

Sukumar Gorai
  • 10,823
  • 4
  • 19
  • 46
0

To avoid this issue, you have to make footer block as noncacheable for cms pages

At layout files, add below code

<default>
<reference name="footer">
    <action method="setCacheLifetime">null</action>
</reference>
</default>

or

<default>
<reference name="footer">
    <action method="setCacheLifetime" />
</reference>
</default>

You can help from

Do not cache footer

http://fbrnc.net/blog/2015/06/cache-and-layout-xml-tricks

Abhilesh Sharma
  • 101
  • 1
  • 9
Amit Bera
  • 77,456
  • 20
  • 123
  • 237
  • I have added these codes in local.xml file but not works. Might be local.xml files code not works. Not sure.

    Also When I disable "Blocks HTML output" in "Cache Storage Management" section in magento backend my footer.phtml code is working fine.

    – Abhilesh Sharma Jun 13 '18 at 06:08