1

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.

asked Nov 21, 2015 at 2:44

1 Answer 1

2

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

Manoj Deswal
5,80325 gold badges29 silver badges50 bronze badges
answered Nov 21, 2015 at 3:23
2
  • 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. 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. Commented Nov 22, 2018 at 11:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.