3

How can I display a text block between two dates? I would like to display a remark on the homepage and possibly on product detail pages, but only for one week in August. I could edit the homepage manually, but if I can set it now and if it works automatically that would be great. Is there a way to do this in magento or do I need a module for it?

1 Answer 1

4

Option 1 - cleanest.
Create a static block with the id home_temporary_block (or any other name). Create a new theme that has in the local.xml layout file this:

<cms_index_index> <!-- layout handle for homepage-->
    <reference name="content">
        <block type="cms/block" name="cms_hp_block" before="-">
                <action method="setBlockId"><block_id>home_temporary_block</block_id></action>
            </block> 
    </reference>
</cms_index_index>

Then edit the homepage in CMS->Pages and under the tab Design section Custom Design set your start date, end date and new theme for fields Custom Design From, Custom Design To and Custom Theme.
Option 2 - not that clean, but still....
An other option would be to create a template file that displays a static block, but before displaying it, check if the current date is in the specified interval.
So add this to the homepage

{{block type="core/template" template="custom/template.phtml"}}

In custom/template.phtml add this code:

<?php 
$now = Mage::getModel('core/date')->gmtDate('U');
$start = Mage::getModel('core/date')->gmtDate('U', mktime(0, 0, 0, 8, 1, 2013));//august 1st 2013
$end = Mage::getModel('core/date')->gmtDate('U', mktime(0, 0, 0, 8, 15, 2013));//august 15th 2013
if ($now >= $start && $now <= $end){//if between selected dates
    //load the block
    $block = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('home_temporary_block');
    //display the block
    echo $block->toHtml();
}

Option 3 - kind of ugly. You can create a static block and show it on homepage, and have a cron that enables/disables it at a specified date.

4
  • Hi marius, is it possible to add a Start date and End date datepicker in the static block itself., in the admin ? Aug 12, 2015 at 9:07
  • 1
    @Manashvibirla By default no.
    – Marius
    Aug 12, 2015 at 9:07
  • by customization, will it be a feasible solution.? Aug 12, 2015 at 9:09
  • Also, in the first approach of the above answer, what if i want to enable/disable the block other than the home page (e.g. product view page), then where will i set the start date and end date ? Aug 12, 2015 at 9:14

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.