Last active
February 11, 2020 07:23
-
-
Save wtorsi/a741947acb287c653ac3bcf94b582ec3 to your computer and use it in GitHub Desktop.
[Twig] display calendar by months using Twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
{%- for month in months -%} | |
<div class="col-6"> | |
<table class="table table-condensed table-calendar bg-white"> | |
<thead> | |
<tr> | |
<th colspan="7"> | |
{{- month|format_date('medium', 'MMM') -}} | |
</th> | |
</tr> | |
</thead> | |
<tbody> | |
{%- set delta = 1 -%} | |
{%- set dow = month|date_modify('first day of this month')|date('w') -%} | |
{%- set start = month|date_modify((dow >= delta ? delta - dow : dow - 7 + delta ) ~ 'days') -%} | |
{%- set weeks = month|date_modify('last day of this month')|date('W') - month|date_modify('first day of this month')|date('W') -%} | |
{%- for week in 0..weeks -%} | |
<tr> | |
{%- set current = start|date_modify('+' ~ (7 * week) ~ 'days') -%} | |
{%- for i in 0..6 -%} | |
{%- set day = current|date_modify('+' ~ i ~ ' day') -%} | |
{%- set disabled = day|date('n') != month|date('n') -%} | |
<td class="{{ disabled ? "disabled" }} "> | |
{{- day|date('d') -}} | |
</td> | |
{%- endfor -%} | |
</tr> | |
{%- endfor -%} | |
</tbody> | |
</table> | |
</div> | |
{%- endfor -%} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment