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?

3
  • what error you getting ? the code which you using is correct, cache problem i think Commented Jun 12, 2018 at 7:46
  • Please share your footer XML code and footer.phtml file full code.
    – kunj
    Commented Jun 12, 2018 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. Commented Jun 12, 2018 at 7:54

3 Answers 3

0

Try this code:

if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
    echo 'You are in Homepage!';
} else {
    echo 'You are NOT in Homepage!';
}
1
  • 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. Commented Jun 12, 2018 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!

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

1
  • 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. Commented Jun 13, 2018 at 6:08

Your Answer

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

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