Contributed by Enrique Bengoechea
Making a calendar is easy with the built-in dates function provided in htmlpp.
Here you have an example of a simple calendar, which you may customize to your needs.
It is issued whenever the block calendar
is built. You must have defined
the global variables $(month)
and $(year)
before building the block.
Making a Calendar: Source Code |
Download:
calendar.htp
(817 bytes) |
1 | .block calendar
2 | <TABLE border=1><TR>
3 | <TH colspan=7>&date("mmmm yyyy","$(year)$(month)01")</TH></TR>
4 | <TR><TH>Sun</TH>
5 | <TH>Mon</TH>
6 | <TH>Tue</TH>
7 | <TH>Wed</TH>
8 | <TH>Thu</TH>
9 | <TH>Fri</TH>
10| <TH>Sat</TH></TR>
11|
12| .- print a number of empty cells depending on which
13| .- day of the week is the first day of the month
14| .if &week_day("$(year)$(month)01") != 0
15| .for i from 1 to &week_day("$(year)$(month)01")
16| <TD></TD>
17| .endfor
18| .endif
19|
20| .- Loop through the maximum number of days a month may have...
21| .for i from 0 to 30
22| .- ...but only if it's a day in the same month
23| . if '&date("mm",&future_date($(i),"$(year)$(month)01"))' eq '$(month)'
24| <TD>&("$(i)+1")</TD>\
25| .- New table row if it's saturday
26| . if &week_day(&future_date($(i),"$(year)$(month)01")) == 6
27| </TR>
28| . endif
29| . endif
30| .endfor
31| </TABLE>
32| .endblock
|
Thus, the following code:
.define month 10
.define year 1999
.build calendar
generates the following output:
October 1999 |
Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
|
|
|
|
|
1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |