Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Display text on a certain day?

Solved by Justin Young View solution

Started by Justin Young 6 years ago · 2 replies · 655 views
6 years ago

Is there a way to display a short text based on the date or even month?

This would be similar to the Fortune plugin, but not random.

6 years ago Solution

Here's a solution

TWIG
{% set message = { "01": 'foo', "02": 'bar' } %} {# each date has a message #}
{% set date = now | date("d") %}
{{ message[date]|default('no data for given day') }}
6 years ago

Nice! Also very useable for weekday messages via changing "d" to "D" and altering the array to elements like
"Mon": 'Go for it! A new week has begun!'

👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Old Man Umby, 1 week ago
2 116 6 hours ago
General · by jeremycherfas, 2 weeks ago
5 205 19 hours ago
General · by lynbor, 7 days ago
2 137 4 days ago
General · by Sebastian, 2 weeks ago
1 135 2 weeks ago
General · by Andy Miller, 3 weeks ago
0 256 3 weeks ago