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?

  • what error you getting ? the code which you using is correct, cache problem i think – Rahul Singh Jun 12 '18 at 7:46
  • Please share your footer XML code and footer.phtml file full code. – kunj Jun 12 '18 at 7:50
  • In footer.phtml I am adding this code at the top area and I have not made any changes in xml file. Also sorry where I can get xml code. – Abi Sharma Jun 12 '18 at 7:54
0

Try this code:

if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
    echo 'You are in Homepage!';
} else {
    echo 'You are NOT in Homepage!';
}
| improve this answer | |
  • 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. – Abi Sharma Jun 12 '18 at 7: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!

| improve this answer | |
  • Not works, this also print the same result always, After flush cache it change result to correct one but again give same result.. – Abi Sharma Jun 12 '18 at 8:19
  • Are you using full page cache? – Sukumar Gorai Jun 12 '18 at 8:20
  • Sorry, What is full page cache. If its extension then we are not using any extension to increase page speed – Abi Sharma Jun 12 '18 at 10:28
  • I am not asking you to add new extension. This type of issues are generally occurs due to FPC extension. – Sukumar Gorai Jun 12 '18 at 10: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

| improve this answer | |
  • 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. – Abi Sharma Jun 13 '18 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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