0

I decide to use Notification Bar extension to show a notification just in home page. But this extension shows the notification on all pages.

I found that there is a notifications.phtml file in app\design\frontend\base\default\template\notificationbar\html\ with this content:

    <?php
/**
 * Datepicker adminhtml configuration control based on the 
 * Mage_Adminhtml_Block_Report_Config_Form_Field_YtdStart control.
 *
 * @author Justin Stern (www.foxrunsoftware.net)
 * @copyright  Copyright (c) 2012 All Rights Reserved, http://www.foxrunsoftware.net
 * @license    FoxRunSoftware License Agreement
 * 
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * 
 * @category design
 * @package  base_default
 */
?>
<?php
/**
 * @see FoxRunSoftware_NotificationBar_Block_Html_Notifications
 */
?>
<?php if ($this->displayNotifications()): ?>
    <div id="notification-bar"><div id="notification"><span class="notification-content"><?php echo $this->getNotificationContent(); ?></span><?php if($this->allowClearControl()) : ?><span class="notification-close"><a title="dismiss this notification">×</a></span><?php endif; ?></div></div>
    <?php if($this->allowClearControl()) : ?>
    <script type="text/javascript">
        $$('#notification-bar .notification-close').first().observe('click',function(event) { var callback = <?php echo ($this->isFixed() ? "function() { \$\$('body').first().setStyle({marginTop:0}); }" : "function(){}") ?>; event.element().up('#notification-bar').fade({duration:0.5, afterFinish:callback}); Mage.Cookies.set("<?php echo $this->getNotificationClearCookieName() ?>","1",new Date((new Date()).getTime() + 365*24*60*60*1000),"/"); });
    </script>
    <?php endif; ?>
<?php endif; ?>

I found that I should alter this line:

<?php if ($this->displayNotifications()): ?>

Is there some way to determine if the page being served is home page?

3

The easiest way is to do this form the local.xml. This way we'll know for sure our changes will be included last.

So add the following in the local.xml removing it from ALL the pages and specifically adding it to just the CMS index (which is the homepage)

<default>
  <remove name="notificationbar_notifications"/>
</default>

<cms_index_index>
   <reference name="after_body_start">
      <block type="notificationbar/html_notifications" name="custom_notificationbar_notifications" template="notificationbar/html/notifications.phtml" />
   </reference>
</cms_index_index>
0
$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();

if($routeName == 'cms' && $identifier == 'home') {
    // for code
}

Try it!

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.