Movable Type User Manual: TEMPLATE TAGS

« Table of Contents


TEMPLATE TAGS

Movable Type templates are composed of special tags embedded within standard chunks of plain text (or HTML, as the case may be). Certain tags are ``container'' tags: they contain what might be called a subtemplate, a chunk of text and MT tags between two other MT tags. Typically a container tag represents either a loop or a conditional.

Non-container tags are simple variable tags: they are placeholders for dynamic pieces of information.

All Movable Type tags are enclosed within less-than greater-than signs, just like HTML tags. You can optionally insert a $ inside these signs, like this:

<$MTEntryBody$>

This can be useful to quickly determine whether a particular tag is an HTML tag or a Movable Type tag.

Movable Type tags take attributes to modify their behavior. Tag attributes work similarly to HTML tag attributes: they are lists of name="value" pairs, separated by spaces. For example:

<MTEntries author="Foo" category="Bar">

(Look at the MTEntries documentation to determine what this does.)

Attribute values must be enclosed in quotes; otherwise they will not be parsed correctly. When using attributes in a tag where you are using the $ character after the start and before the end tags, you should place the attributes before the end $ character. For example:

<$MTEntryDate format="%B %e, %Y"$>

Some tag attributes are global; they apply to all Movable Type variable substitution tags. Global attributes are discussed below in Global Tag Attributes. Other attributes are tag-specific; they apply only to certain tags. These attributes are listed along with the tags that they apply to, below.

Some Movable Type tags are context-sensitive. For example, it only makes sense to use an MTComments tag in the context of a particular entry: for example, in a Comments Popup template, or in an archive template designed for use with Individual entry archives.

Weblog Data

Entry Listings/Archive Pages

Comments

Comment Previewing

When creating the Comment Preview Template for use in previewing comments before they are posted to your site, you should use the following tags. All of these tags have the same meaning as the similarly-named tags in Comments, above; the only different is that these tags are used for the comment that you are previewing, whereas the others are used inside of an <MTComments> block.

Archive Templates and Master Archive Index

The following template tags and variables apply to your archive pages and to your Master Archive Index.

Category-Related Tags

The following tags can be used to display a list of the categories in your weblog, and information about each category (ID, label, etc.).

The hierarchical structure of categories can be reflected in a template as well. Normally, a template designer would create a block of template tags that express a design for one entry in the category display, and this block would be repeated for each top-level category, much like other tags such as MTEntries and MTComments. To display the children of each of these categories, insert the <MTSubCatsRecurse> tag at the point where a list of children should be displayed using exactly the same format defined in that block.

For a given <MTSubCategories>...</MTSubCategories> block of template code, if <MTSubCatsRecuse> is included in that block, the block is then repeated for each category for which the current category is a parent (e.g. if, from our previous example, 'Entertainment' is the current category, <MTSubCatsRecurse> will run 'Books' and 'Music' through the block of template tags).

Getting the output you want usually requires making use of the conditonal block tags <MTSubCatIsFirst> and <MTSubCatIsLast>, which will render their contents if the ``current'' category is first or last (respectively) in the list of sibling categories. This is usually required to produce the right HTML tags in structuring a hierarchical list.

For example, the following will produce nested unordered lists to display the category hierarchy:

    <MTSubCategories> 
    <MTSubCatIsFirst><ul></MTSubCatIsFirst>
    <li>
    <MTCategoryLabel>
    <MTSubCatsRecurse>
    </li>
    <MTSubCatIsLast></ul></MTSubCatIsLast>
    </MTSubCategories>

See below for more information about each tags.

Calendar Display Tags

The following tags can be used to output a calendar display of your entries. The calendar display is not restricted to construction using HTML tables; the tags are sufficiently generic that you could use them to create a calendar in many different forms.

Here is the markup for a fairly standard calendar display; this will display a calendar for the current month.

<table border="0" cellspacing="4" cellpadding="0" summary="Monthly calendar">
<caption><$MTDate format="%B %Y"$></caption>
<tr>
<th abbr="Sunday" align="center">Sun</th>
<th abbr="Monday" align="center">Mon</th>
<th abbr="Tuesday" align="center">Tue</th>
<th abbr="Wednesday" align="center">Wed</th>
<th abbr="Thursday" align="center">Thu</th>
<th abbr="Friday" align="center">Fri</th>
<th abbr="Saturday" align="center">Sat</th>
</tr>
<MTCalendar>
<MTCalendarWeekHeader><tr></MTCalendarWeekHeader>
<td <MTCalendarIfToday>bgcolor="#EEEEEE"</MTCalendarIfToday> align="center">
<MTCalendarIfEntries><MTEntries lastn="1"><a href="<$MTEntryLink$>"><$MTCalendarDay$></a></MTEntries></MTCalendarIfEntries>
<MTCalendarIfNoEntries><$MTCalendarDay$></MTCalendarIfNoEntries>
<MTCalendarIfBlank>&nbsp;</MTCalendarIfBlank></td>
<MTCalendarWeekFooter></tr></MTCalendarWeekFooter>
</MTCalendar>
</table>

NOTE: the computation of the calendar display is relatively expensive, so if you wish to place the same calendar on every page of your site, it is advisable to create the calendar in an index template, then use server side includes or PHP (or any other dynamic webserver tool) to include that file in each of your pages.

TrackBack Tags

These are tags related to the TrackBack system.

Search Results Tags

The following tags can only be used in your search templates.

Miscellaneous Tags

These are tags which really don't fit in any of the above categories.

Global Tag Attributes

Global tag attributes can be used in any variable substitution tag (a tag that is replaced with a value--in contrast to a container tag, which ``contains'' a set of markup and other tags). However, this does not mean that they would necessarily make sense when used in any tag; it is up to the user to determine when using a particular tag attribute might not make practical sense.

You should use a global attribute just as you would use a tag-specific attribute: as a name="value" pair within the tag. For example:

<$MTEntryExcerpt encode_html="1"$>

This will be replaced with an HTML-encoded version of the excerpt.

Here is a list of the global tag attributes:

Date Tag Formats

Movable Type uses standard strftime format strings to describe dates and times. (However, note that strftime itself is not actually used to perform the formatting.) In any date tag, you should use the format attribute to specify the format string, like this:

<$MTDate format="%B %e, %Y %I:%M %p"$>

The above format is actually the default format for English date formatting, and creates a date looking like this:

September 20, 2001 11:44 PM

The language used in weekday names, month names, and AM/PM specifiers can be chosen in the Weblog Configuration as Language for date display. The default language used is English.

You can override the default language setting by using the language attribute to specify the language; this will apply only for the particular date string that you are formatting. Here is the list of available language tags: cz, dk, nl, en, fr, de, is, jp, it, no, pl, pt, si, es, fi, se.

Here is a list of the format specifiers.

NOTE: As of version 2.0 of Movable Type, %Z is no longer supported. If you want the timezone, take a look at the <$MTBlogTimezone$> tag.


Copyright © 2001-2005 Six Apart. All Rights Reserved.