Extension:Winter/Example 4

You may see this example live at wiki.swiftlytilting.com

= Winter 2.0 = The following code is valid for Winter 2.1.0 and above

Code
= Winter 1.5 = The following code is valid for Winter 1.3 and above.

Code
&lt;div style="border:1px solid black;width:22em;text-align:center;padding-bottom:.5em"> &lt;span style="background-color:#cccccc; padding:.25em; margin:.5em; margin-bottom:1.5em; margin-right:.5em; width:2em;"> August 2024 &lt;/span> &lt;/div>

Explanation
The above code will produce a simple calendar for the current month. Lets take a look at each section of code to get a better idea of whats going on.

Disables the cache so that the calendar is drawn each time. Otherwise the calendar page would only show the current month when it was cached.

The above setvar commands demonstrate how to create rudimentary arrays. Wiki variables like CURRENTMONTH are replaced before Winter ever sees them, so MONTH_August appears as MONTH_August to Winter.

Define a function to display the date box. this is to make the loop code easier to read

Sets WeekStart to ( 8 - ((CURRENTDAY - CURRENTDOW) mod 7)) which will away give you the day of the week that the month started on in the form of 0 - 6 just like CURRENTDOW.

&lt;div style="border:1px solid black;width:22em;text-align:center;padding-bottom:.5em"> &lt;span style="background-color:#cccccc; padding:.25em; margin:.5em; margin-bottom:1.5em; margin-right:.5em; width:2em;"> August 2024 &lt;/span>

Draw the calendar header in html

is in the code below)

}}

This nested for loop draws out each box, first by day then by week. It is equivalent to the following PHP code:

for ($day = 1; $day &lt;= $days_in_month;) { for ($i = $WeekStart; $i &lt; 7; $i++, $day++) { ShowDay( (($day &lt; 10) ? : "0" : "") . (($day > $days_in_month) : 00 : $day)   }    echo '&lt;div "style=clear:left">&lt;/div>';    $WeekStart = 0; }

Please note this code:

ShowDay( (($day &lt; 10) ? : "0" : "") . (($day > $days_in_month) : 00 : $day)

displays a leading 0 if the date is less than 10, or 00 if the date is greater than the days in the month.

&lt;/div>

Closes box