Skip to content

Instantly share code, notes, and snippets.

@mdcpepper
Created May 19, 2014 14:14
Show Gist options
  • Save mdcpepper/9bd219464aa4a9d124dc to your computer and use it in GitHub Desktop.
Save mdcpepper/9bd219464aa4a9d124dc to your computer and use it in GitHub Desktop.
{% macro datesBetween(startDate, endDate, currentDate = null) %}
{% import _self as self %}
{# initialize the currentDate from the startDate #}
{% if currentDate is null %}
{% set currentDate = startDate %}
{% endif %}
{# echo the current date, or the startDate if it's the first run #}
<li>{{ currentDate }}</li>
{# add a day #}
{% set currentDate = currentDate|date_modify('+1 day') %}
{# if we're not at the endDate yet, call ourself and carry on #}
{% if currentDate <= endDate %}
{{ self.datesBetween(startDate, endDate, currentDate) }}
{% endif %}
{% endmacro %}
{% import _self as self %}
{% set startDate = now %}
{% set endDate = now|date_modify('+1 week') %}
<ul>
{{ self.datesBetween(startDate, endDate) }}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment