TEMPLATES

### Movable Type User Manual: TEMPLATES

« Table of Contents

- TEMPLATES

- Index Templates
- Archive Templates
- Template Modules
- Miscellaneous Templates
- Editing a Template
- Default Templates

# TEMPLATES

Templates in the Movable Type system are your method of defining the design and layout of your site. Templates describe where you want your content (that is, your entries and archives), what that content should look like, and so on. Generally your templates will be made up of HTML, interspersed with Movable Type template tags and variables (see TEMPLATE TAGS), but this is not a technical limitation; you can use Movable Type to generate plain text, HTML with server-side includes, PHP, and any other text-based language.

You can edit your weblog's templates, and define new templates, by logging in to Movable Type, selecting a weblog, then clicking List & Edit Templates.

There are several different types of templates in Movable Type.

## Index Templates

Index templates are your main entry listings. Unlike many other weblog management systems, Movable Type supports multiple index templates; this means that you can publish your main entry listings in several formats, for example, like one listing in HTML, and one in XML. By default, an index template displays the last `N` days worth of entries, where `N` is defined in your weblog configuration. For example, if you set the number of days displayed on the index to `7`, Movable Type will, by default, display all entries from the last 7 days on all of your index templates. Note that 7 days means the last 7 consecutive days, not necessarily the last 7 days on which you posted an entry. So if you have posted on just 3 of the last 7 days, only the posts from those 3 days will be listed on your main indexes.

As mentioned above, displaying the last `N` days of entries is the default behavior for index templates; this behavior is customizable, however, through the `MTEntries` tag (see below); for example, you might set your RSS index (for RSS syndication) to display your last 15 entries, no matter the date.

## Archive Templates

Archive templates define the look and feel or your weblog archives. For each archive type that you choose (see ARCHIVING), you can associate multiple archive templates with that archive type; this allows for different ``views'' of the same set of archived entries. For example, you might wish to create two different views of your monthly archives: a page containing each of the entries for a particular month, and a calendar view of that month. Or, you could use different templates to create hi-fi and lo-fi versions of your archives.

When an archive type is rebuilt, all of the archive templates associated with the archive type are rebuilt--this allows you to automatically maintain several views of the same archived entries.

Movable Type ships with three archive templates: one for the date-based archives (`Monthly`, `Weekly`, and `Daily`), one for your `Category` archives, and one for your `Individual` entry archives.

To define a new Archive Template, go to List & Edit Templates, and click `Create new archive template`. Name the template, then define the layout for the archive page using Movable Type template tags. After you have saved the new archive template, go to the Archiving section of your Weblog Configuration, and click the `ADD NEW...` button; in the popup window, select the template you just created from the Template: pulldown menu, and select the archive type with which you'd like to associate that template from the Archive Type: menu. Then click `ADD`.

## Template Modules

Movable Type allows you to extract common chunks of HTML code into templates that you can then include in your other templates; in Movable Type, these common templates are called `Template Modules`. An example of the use for such a template might be a header that you use throughout your site. You can create a new template module called `Header`, paste in the common header code, then save the new template. You can then include this code in all of your other templates using the `MTInclude` tag:

    <$MTInclude module="Header"$>

This tag will be replaced by the contents of the `Header` custom template.

This allows you to keep all common code in one place, so that if you need to modify it, you only need to modify it in one place.

## Miscellaneous Templates

These are the templates that don't fit as Index Templates, Archive Templates, or Custom Templates. Currently, the templates in this category are:

- Comment Listing Template
  This template defines the layout of your comments pages, if you choose to use popup windows for your comments (see Comments, above).

- Comment Preview Template
  This template defines the layout of your comment preview pages, if you choose to use comment previews (previews are enabled by default).

- Comment Error Template
  This template is used to define the error your users see if, when they submit a comment, there is an error in their submission (name and email address are not filled out, invalid email address or URL, etc). You can use this template to let users fix the error in their comment submission, then post the comment.

- TrackBack Listing Template
  This template defines the layout of the popup window listing TrackBack pings sent on a particular entry in the system (see the documentation on the TrackBack system).

- Uploaded Image Popup Template
  When you upload an image, you have the choice of creating a new entry with that image embedded or with a link to the image in a popup window. If you choose the latter, and if you have defined a layout for the `Uploaded Image Popup Template`, an HTML file will automatically created that to contain the image in a popup window. There are three template tags that you can use in this template: `<$MTImageURL$>`, `<$MTImageWidth$>`, and `<$MTImageHeight$>`.

## Editing a Template

After selecting a template to edit in the `List & Edit Templates` screen--either by clicking on the name of an index template or a template module, or by clicking the `EDIT` button for the archive or miscellaneous templates--you will be presented with the `Edit Template` screen. Depending on the type of template you are editing, or whether you are editing a template module, the template-editing screen will differ slightly in appearance. For example, only on an `Index Template` will you be able to assign an `Output file`.

Here are the fields you may be presented with on the `Edit Template` screen:

- Name
  The name of the template, which will be used for identification purposes in the `List & Edit Templates` screen. In addition, when including a template module using `<MTInclude>`, you will need to specify the name of the template module to include; that name will be the name that you enter here.

  The template name is editable only for index templates and template modules; it is assigned automatically for archive and miscellaneous templates.

- Output file
  When editing an index template, you must specify a filename where the output of the template will be stored. For example, the output file for your main index template might be index.html.

  The output file applies only to index templates. It can be either a relative path (eg. file.html), in which case it is relative to your Local Site Path, or a full path rom the root of the filesystem (eg. /full/path/to/file.html).

- Rebuild this template automatically
  When editing an index template, you have the option of rebuilding the template automatically (every time you save an entry, rebuild all files, or rebuild indexes), or manually. Most of the time, you should just choose to rebuild an index template automatically. There are times, however--for example, when you are using index templates to manage primarily static content in your site--when you do not need to rebuild an index template every time you add a new entry. In such times, rebuilding static index templates needlessly slows down the process of adding a new entry.

  Thus, you can use this option to turn off automatic rebuilding for an index template. If you turn off automatic rebuilding, the ONLY WAY to rebuild the index template is to click on its name in List & Edit Templates, then click the REBUILD button below the text-editing box. This will force a rebuild of the particular index template.

- Link this template to a file
  Often it is easier to edit the contents of a template outside of the Movable Type web application; for example, many people like using a text editor with code highlighting to edit their HTML. Linking a Movable Type template to an external file allows you to edit your templates using an external application, while keeping the copy of your template that is inside Movable Type in sync with the external file. The synchronization process works in both directions: when you load a template for editing, the linked file is checked for a more recent copy; and when you save a template through Movable Type, the linked file is updated with your changes.

  The value of the linked filename should be either a full path on the filesystem to your external file, or a path relative to the `Local Site Path` for your weblog. The file extension cannot be: .cgi, .pm, .pl, or .cfg, for security purposes, and so you do not overwrite your Movable Type program files. For example, if you would like to maintain your `Main Index` template through an external editor, you might set the linked file to index.html.tmpl. You can then edit this file externally and save it to your webserver; when you rebuild, Movable Type will grab the latest version of the linked file index.html.tmpl and use that as the template (it will also update the copy of the template in the Movable Type database, so that the next time it needs the template, it can use the version in the database).

  NOTE: when you create a new template without specifying a template body, and link it to a file that already exists, the contents of that file will be pulled in to the template. If you do specify a template body, however, and the linked file already exists, that linked file will be overwritten with the template body you specified.

  Linking a template to an external file is optional; you are free to maintain all of your templates through the Movable Type application itself, if you wish.

- Template body
  The body of your template, containing template tags (see TEMPLATE TAGS) and other markup (HTML, for example).

## Default Templates

Movable Type ships with a set of default templates that are customizable through stylesheets; the same template markup can be made to look completely different by inserting a new stylesheet. You can view the default templates themselves at http://www.movabletype.org/default_templates.shtml .

To select a new style for your weblog, follow these instructions:

1. Log in to Movable Type, select the weblog you wish to edit, then click `List & Edit Templates`.

2. In the list of Index Templates, you will see a template called `Stylesheet`; open this template for editing.

3. The prebuilt stylesheets used to customize your pages are located at http://www.movabletype.org/default_styles.shtml . On this page, you can view screenshots of each style; once you have selected the style you wish to use, copy the contents of the text box, and paste those contents into the `Template body` box of the template you opened for editing in Step 2.

4. Press the `SAVE` button to save the new stylesheet.

5. You will be prompted to rebuild your site; click the `REBUILD` link, select `Rebuild Indexes Only` from the pulldown menu, and click the `REBUILD` button.

6. When the rebuild has completed, your site will now be using the new stylesheet.

   NOTE: some browsers (Internet Explorer for Windows, for one) refuse to reload a stylesheet from the webserver once they have fetched it once; if, when you view your site, nothing has changed, you should empty your browser cache and try again.

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