Leo's MovableType Tips

by Leo A. Notenboom

by Ask Leo!

A Couple of Definitions

So just what is a CMS?

A CMS or "Content Management System" is nothing more than a database, a repository in which to keep - you guessed it - content. The value of a CMS is that it typically keeps your content in a certain structure with additional information that allows the content to be easily processed in smart ways.

MovableType is such a system.

MovableType uses the concept of an "entry" to manage how your content is structured. Entries are further structured as having a Title, a Body, an Excerpt, an Author, and ancillary information like a publication date, a "published" status and more.

Entries can be assigned to one or more "categories" that allow you, using MT, to further organize your content.

Since it was developed initially and primarily as a blogging tool, MT supports features such as:

MT supports a robust extensibility model that allows you to add custom features. In fact, libraries of extensions known as "plug-ins" are available, often for free. I'll be referring to a couple of them and will also include a couple of simple plugins here.

One of the defining characteristics of a CMS is what I'll call its "build" versus "process" model. Some CMSs create their output dynamically: processing it each time that it's requested by a site visitor. The "page" that a visitor sees doesn't actually exist in that form until he or she requests it by visiting the page's URL. MovableType, on the other hand, primarily uses a "build" model where, on publication, MT creates the .html pages that are served up when a user visits the site. As a result, MT may actually not be involved when a page is displayed - only when the content is changed, such as when a comment or trackback is added, or a new entry is published.

So, just what is a template?

There is a lot of confusion around the word "template". In the general, "website" sense, it can mean anything from a vague description of the look and feel of a site, to a specific HTML and/or CSS page that defines in detail which pixel goes where.

MovableType has a much more specific meaning of "template", as do most CMSs.

The definition I'll use is this:

A template is a text file which contains instructions to the CMS defining how content should be transformed into published results.

Sadly that's probably too general to be helpful yet, so let's look at how MovableType processes templates.

There are three types of objects in a MovableType template:

Let's look at each in turn.

A directive tells MT what to do. For example, somewhere in your index template for your blog's home page, you probably have something that looks like this:

<MTEntries>
  ...
</MTEntries>

The MTEntries instructs MT to repeat everything between it and the ending /MTEntries tag once for each entry (by default, that's actually once for each entry published in the last 'N' days, where 'N' is a weblog configuration item).

A variable is replaced with data from the CMS. If we expand that example one step further:
<MTEntries>
  <$MTEntryTitle$>
</MTEntries>

MTEntryTitle is replaced with the value of the title for the entry in question. So MTEntries repeats what's inside of it for each entry, and what's inside of it outputs the title for each.

Everything else is simply copied to the output. Again, let's expand on the example:

A List of Titles:
<MTEntries>
  Article Title: <$MTEntryTitle$>
</MTEntries>

This time when the template is processed, the string "A List of Titles:" is output, followed by a line for each Entry that has the string "Article Title:" followed by the entry's title.

Not a particularly useful example, but a simple one.

Note that nothing I did had anything to do with HTML. Nothing. That's an important concept, because template processing is just processing text. Anything that can be represented in text can, potentially, be created by processing a template through your CMS. This opens up a wide range of possibilities for our tips and tricks. As one example, one of the tips later will use a template to generate PHP scripting code, with no HTML involved at all.