Htmlpp

Source Code Examples

 
 Home 
 Introduction 
 Download 
 Docs 
 Support 
 Examples 
 Add-ons 
Full Sites Snippets

Making a Calendar

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
12
3456789
10111213141516
17181920212223
24252627282930
31

Previous
Previous Snippet
Using Blocks as Macros
Snippets List
Snippets List
Next Snippet
A macro for inserting images
Next
iMatix
 
Copyright © 1996-99 iMatix Corporation.
Hosted by OpenAvenue.com. Made with Htmlpp. Powered by Xitami.
 
Updated: December 20, 1999
Feedback