Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Display text on a certain day?

Solved by Justin Young View solution

Started by Justin Young 6 years ago · 2 replies · 600 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 jean-louis67, 3 days ago
2 83 2 days ago
General · by Andy Miller, 7 days ago
0 147 7 days ago
General · by Veehem, 1 week ago
0 146 1 week ago
General · by milkboy, 1 week ago
0 142 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago