0

I need to show an element wrote in HTML into a footer page, only if you're in a specific page ( website homepage, category pages, search results and product pages).

I don't want use statics blocks because the element that I've to show is a simple image with a small amount of text, so the best way that i think to add an "if" that shows the code only if you're in the pages quoted upstairs, but I don't know how can I write the "if condition".

I'm waiting for the answers.

2
  • Which is your Magento version? Jul 19, 2016 at 14:44
  • Hi, I'm using Magento ver. 1.9.1.0 Jul 20, 2016 at 8:56

1 Answer 1

0

You can use the following structures to determine requested page Mage::app()->getRequest()->getRouteName(); for route name Mage::app()->getRequest()->getActionName(); for action name Mage::app()->getRequest()->getControllerName(); for controller name Mage::app()->getRequest()->getControllerModule(); for module with namespace Mage::getSingleton('cms/page')->getIdentifier(); for id of cms page

for example if you need to output your cms block only on Terms and Conditions page you can use

<?php if(Mage::app()->getRequest()->getControllerModule() == 'Mage_Cms' && Mage::getSingleton('cms/page')->getIdentifier() == 'terms-and-conditions'): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_cms_block_identifier')->toHtml() ?>
<?php endif;?>

in app/design/frontend/your_package/your_theme/default/template/page/html/footer.phtml

Hope it will be usefull for you.

1
  • Hi, thank you for the reply. Unfortunately I don't understand well (I don't know a lot about php) how can I write down the php code, I tried it but it doesn't work. May you help me? Jul 20, 2016 at 8:55

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.