Chapter 3: Templates and Layout
Displaying a Calendar Layout
Problem
You want to create a calendar layout in your template.
Solution
Use the template tags prefixed with MTCalendar.
Discussion
Movable Type includes a collection of template tags prefixed with MTCalendar; these can be used for creating calendar layouts that serve either navigational or display purposes. MTCalendar tags are sufficiently generic to create calendars in many different formats; however, HTML tables are the most common,
- MTCalendar
MTCalendaris a container tag representing a calendar month that lists a single calendar "cell" in the calendar display. A calendar cell is either a day of the month or a blank; this is used to represent a day in a different month.This tag takes an optional attribute
month, which, if present, specifies the desired calendar month and year. If the value of this attribute is the stringthis, the calendar will be created in the surrounding date context; this means that, for example, in an archive template, you can use:<MTCalendar month="this"> ... </MTCalendar>This represents the month of the archive currently being viewed. This will work for
Individual,Daily,Weekly, andMonthlyarchives, but not forCategoryarchives.If the value of the
monthattribute islast, the calendar will be created for the previous month, relative to the current date.If you'd like to create a calendar for a specific month, you can use the
monthattribute to specify the exact month and year inYYYYMMformat. For instance to display the calendar for April 2005 themonthattribute would have a value of "200504."If the
monthattribute is not provided, the calendar will display the current month.If you would like to only display entries from a certain category, you can optionally specify the
categoryattribute, giving it the category label.<MTCalendar month="200504" category="Foo"> ... </MTCalendar> - MTCalendarDay
The numeric day of the month for the cell.
- MTCalendarIfEntries
A conditional tag that will display its contents if there are any entries for this day in the weblog.
- MTCalendarNoEntries
A conditional tag that will display its contents if there aren't entries for this day in the weblog. This tag predates to introduction of MTElse that could be used with MTCalendarIfEntries to replace this tag.
- MTCalendarIfBlank
A conditional tag that will display its contents if the current calendar cell is for a day in another month.
- MTCalendarWeekHeader
The contents of this tagset will be displayed before a calendar week is started.
- MTCalendarWeekFooter
The contents of this tagset will be displayed after a calendar week is ended.
Prior to version 3.2, a calendar display was included in the Main Index template of the default template set. This markup has since been removed to speed up rebuilding times.
The following is the layout that was included in the default templates but with the styles updated for Movable Type 3.2 (thanks to Arvind Satyanarayan).
<h2 class="module-header"><$MTDate format="%B %Y"$></h2>
<div class="module-content">
<table summary="Monthly calendar with links to each day's posts">
<tr>
<th abbr="Sunday">Sun</th>
<th abbr="Monday">Mon</th>
<th abbr="Tuesday">Tue</th>
<th abbr="Wednesday">Wed</th>
<th abbr="Thursday">Thu</th>
<th abbr="Friday">Fri</th>
<th abbr="Saturday">Sat</th>
</tr>
<MTCalendar>
<MTCalendarWeekHeader>
<tr>
</MTCalendarWeekHeader>
<td>
<MTCalendarIfEntries>
<MTEntries lastn="1">
<a href="<$MTEntryPermalink$>"><$MTCalendarDay$></a>
</MTEntries>
</MTCalendarIfEntries>
<MTCalendarIfNoEntries>
<$MTCalendarDay$>
</MTCalendarIfNoEntries>
<MTCalendarIfBlank> </MTCalendarIfBlank>
</td>
<MTCalendarWeekFooter>
</tr>
</MTCalendarWeekFooter>
</MTCalendar>
</table>
</div>
</div>
As you can see, calendar layouts get complex rather quickly. The computation of the calendar display can significantly extend the processing time involved in rebuilding pages. It is generally recommended that these tags be applied judiciously, if at all, to your templates.
For the full list and descriptions of all calendar tags see Appendix A.




Comments
Thanks for posting this. Arvind's calendar code should either have a
tag at the top or one fewer tags at the bottom.Posted by: cww
|
March 11, 2007 11:05 AM