Hide content based on date

Using the advanced jinja2 templating to hide a piece of content depending on the date. This can be used to have something show up before/after/during a date range.

This uses our to_date jinja filter. Take note of the greater than and less than operators.

The to_date is parsed as the first minute and hour of the day so using greater and less than operators is the best way to write the conditionals.

Today, future, or past comparisons

is_today

Show something if the date is today

{% if '2018-12-11'|to_date|is_today %}
<p>I will show if Dec 12, 2018 is today</p>
{% endif %}

is_future

Show something if the date is in the future

{% if '2018-12-11'|to_date|is_future %}
<p>I will show if Dec 12, 2018 is in the future</p>
{% endif %}

is_past

Show something if the date is in the past

{% if '2018-12-11'|to_date|is_past %}
<p>I will show if Dec 12, 2018 is in the past</p>
{% endif %}

Combining the above filters

Show something if the date is today or in the future

{% if '2018-12-11'|to_date|is_today or '2018-12-11'|to_date|is_future %}
<p>I will show if Dec 12, 2018 is today or is in the future</p>
{% endif %}

Using now to compare to the current day and time

The now is the current date and time

Starting on a date

{% if now > '2018-12-11'|to_date %}
<p>I will start showing on Dec 11, 2018</p>
{% endif %}

Up to a date

{% if now < '2018-12-11'|to_date %}
<p>I will stop showing on Dec 11, 2018</p>
{% endif %}

Date range

{% if now > '2018-12-01'|to_date and now < '2019-01-01'|to_date %}
<p>I will show for the whole month of December</p>
{% endif %}