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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Display text on a certain day?

Solved by Justin Young View solution

Started by Justin Young 6 years ago · 2 replies · 491 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 Jerry Hunt, 4 days ago
2 76 7 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago