I want to add the ability to do a date check inside a CMS Static Block. Something like this:

{{if date == '2015-12-25'}}Merry Christmas!{{else}}It's not Christmas{{/if}}

However, I'm not sure how to introduce new functionality like this. I haven't been successful even using {{if}} statements like this with existing variables.

Some pointers on getting {{if}} statements working, and adding custom variables which can be accessed this way should be enough. I can populate said variable with the date pretty easily.

1 Answer 1


you can create block and phtml file and can call that in CMS page. In phtml file you can add IF-ELSE statement.

Here is example to display newsletter block in CMS page:

Place below code where you want to display NEWS LETTER box.

<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>

Call in CMS page:

{{block type="newsletter/subscribe" name="newsletter" template="newsletter/subscribe.phtml"}} 

Note: You can create simple block and phml file like subscribe.phtml and add condition to that file:

 {{if date == '2015-12-25'}}Merry Christmas!{{else}}It's not Christmas{{/if}}

Hope it will help you

  • 1
    The problem is that while I, the developer, am perfectly comfortable working with a phtml file, the content entry staff can't be mucking with phtml files in Git and pushing changes across multiple servers. I'm looking for a way to enable them to do this logic themselves in the CMS.
    – Tyler V.
    Commented Nov 21, 2015 at 3:39
  • Then edit the adminhtml and add time input boxes and code a logic so that the static block does not show if it is not in the time which you have specified. And it should always show if no date is entered at all. You will have to extend the cms static block model to add your time attributes.
    – Black
    Commented Nov 22, 2018 at 11:56

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.