‘Is Home Page’ conditional or Check if you are on the Home page in Magento 1.4 & 1.5

Written by Adrian Hart

Topics: Magento, Web Design

Do you need to put some content on the Home page of your Magento site, but not on others? Here’s how:

Open the relevant .phtml template file which contains the code you want to show on the Home page. Then add the code below depending on which version of Magento you are using…

In Magento version 1.4.x you need to run a check to see if the current URL matches the Home page URL. This piece of code is called a conditional. Our conditional to check if we are on the Home page would look like this…

[code]<?php if( $this->getUrl(”) == $this->getUrl(‘*/*/*’, array(‘_current’=>true, ‘_use_rewrite’=>true)) ):?>
Your HTML here…
<?php endif; ?>[/code]

In version 1.5, the Magento developers were kind enough to include a new global function…

[code]$this->getIsHomePage();[/code]

So if you use Magento 1.5.x or newer, can use this conditional in our .phtml file…

[code]<?php if( $this->getIsHomePage() ):?>
Your HTML here…
<?php endif; ?>[/code]

Much neater!

Leave a Comment Here's Your Chance to Be Heard!