An Introduction to Movable Type Templates
If you’ve installed Movable Type recently, there’s a fair chance you looked at the templates and were immediately overwhelmed. Don’t feel bad, you’re not the only one. By default, MT ships with no less than 56 different templates — all to publish a blog with a single style. You might find yourself asking…
What are MT templates for, anyway?
The templates in Movable Type format the output of your blog. When you write a blog entry and click Publish, MT figures out — based on the date, category, etc. — which of your template files to use in generating new pages on your blog. It reads each template, plugs in the data from your entry, then outputs the new file as part of your blog.
As you poke around in the templates, you’ll find some of them refer to other templates, while still others don’t seem to be used at all. And while this can make MT confusing, it also makes it very powerful. All those templates make customizing your blog much easier.
To understand MT templates, you need to understand the different types and what we use them for. MT templates are all about context. The context of a template determines what MT tags you can use within that template. It’s also possible to establish your own context within a template to customize the output. For example, the
<mt:entrytitle> tag only makes sense in the context of an
<mt:entries>. The individual entry archive establishes that context automatically. But, if you wanted to put a “Featured Entry” in your sidebar, you would need to create an
<mt:entries> context within the sidebar.
We’ll get deeper into this in future posts. For now, just keep in mind that context is important for tags, and templates help to establish that context.
Let’s take a look at the different types of templates:
Archive templates are used to publish entries and pages, either individually or grouped together based on category, date, or author. How an archive template gets published depends on its type (assigned when you create the template) and the archive mappings associated with it.
Archive Template Types
There are three different types of archive templates. The type of template determines what context the template has when it’s published:
- Entry – Entry templates are for individual blog entries. They have an
<mt:entries>context, which is filtered down to a single entry. You can use tags like
<mt:entrybody>, and others. Typically, this is the template you’ll use to publish an entry and its comments.
- Entry Listing – Entry listing templates are for a group of entries. These are your category archives, date-based archives, or author-based archives. They filter the entries to publish based on the archive mapping (more on that in a bit). These templates create a context for tags like
<mt:archivetitle>, as well as more specific tags based on what kind of archive it is.
- Page – Templates for individual pages. These tend to be very similar to Entry templates, since Pages are just entries that exist outside the flow of the blog.
Before you can publish an archive template, it needs an archive mapping. The mapping tells MT where to publish the files and, in the case of entry listings, what type of archive to publish. An archive template can have multiple mappings. This can be used to publish the same templates in different locations. With entry listings, this allows you to use the same template to publish all your archives — categories, date-based, and authors.
Template modules are snippets of template code that are called from other templates. If you are familiar with PHP or SSI, think of it as an include. In fact, that’s exactly how you use it:
Template modules do not get published on their own, only when they’re included in another template. You use them for pieces of code you want to reuse. They make it easy to have the same header and footer across all your pages, for example. Anytime you find yourself using the same code in multiple templates, it’s a good idea to evaluate whether you should pull that code out and put it into a module.
System templates are used for pages that MT has to generate based on an action taken by a reader, such as posting a comment or searching your blog posts. These have their own contexts, and they have a few quirks because of how they’re generated. We’ll explore system templates more in an upcoming post.
Widgets are just template modules, but by declaring them as widgets we can use them in Widget Sets. Widget Sets give us an easy drag and drop interface for customizing our sidebars, footers, and more.
Backup templates are copies of templates that have been replaced by MT. This can happen if you use the Style Catcher to change the look of your blog, or if you use “Refresh Templates” to restore your templates to the defaults.
I recommend taking a look at the different templates to get an idea of how they’re structured. We’ll go deeper into this in future posts, but for now just try to get a sense of how the different templates are connected. You can do this by opening the templates and looking at the information to the right of the template. This will tell you what template modules and widgets are included in the template, and what MT tags are used. The tags link to the MT documentation, which can be useful for learning what the tags do.
Have a question about MT templates? Let me know in the comments.