The following content has unclosed HTML tags: BR/ (3 open)
Customizing Your Published Blogs
Like any basic content management system, templates control the content presentation layer for all pages published by Movable Type. The templates provide a generic framework of content which is consistent between all pages published with the template in addition to placeholders for variable content such as author, entry and weblog information. This chapter covers the following topics in order to introduce and illustrate the use of templates for structure and consistency:
Introduction to Movable Type Templates
Movable Type Template Classes
Movable Type Template Tags
Customizing your Blogs Templates
Presentation is as important as content, so Movable Types templating system allows you to produce pages that showcase your content exactly as you wish. Templates describe where you want to put your content and what that content should look like, using special markers (tags) that are typically mixed with another markup language such as HTML or XML. When you perform a site rebuild, templates are merged with content to create a page that visitors can view in their web browsers. The template engine is crucial to automating this process.
When a new weblog is created, it is provisioned with its own distinct set of default templates that produce the files listed in the previous section. Blog Administrators or any user with template management privileges can view and edit these templates.
Most of the non-variable content in the templates is comprised of basic HTML tags (or XML for feeds) and surrounding text. The areas for insertion of variable content are marked by Movable Type template tags. These tags are very similar in their appearance and function to HTML tags, giving template designers a familiar set of tools to work with and eliminating the need to learn an additional programming language just to change the display of the entries on a weblog.
The familiarity of the template tags combined with a model of separation of content and presentation allows for both the push-button publishing ease-of-use and ultimate control over the final published product that Movable Type has always been known for.
In order to give you a solid frame of reference for the topics covered in this chapter, we recommend that you first publish at least one entry with a category assigned. This will create, in a default configuration, at least one of each type of page Movable Type publishes. Refer to both the administrative interface and the published weblog throughout this chapter.
The steps for accessing and managing your templates are outlined here, followed by a detailed description of the components of the template listing tables.
2. Click the TEMPLATES link found in the Configure section at the top of the left navigation bar. This will open the template listing screen for your blog.
With your templates listing page open, youll notice its organized into four tabbed sections, grouped by template type: Indexes, Archives, System and Modules. Each tabbed page displays the corresponding template listing table which facilitates access to and management of each template.
The template listing screen contains the following elements:
Tabs for each template type: Index, Archive, System and Modules
A listing of all templates for the current template type with basic information for each.
An action bar which facilitates various actions (e.g. delete) that can be performed on one or more templates
A link to create a new template of the current type, with the exception of System templates.
A link to your weblogs publishing settings screen
A search field which allows for fast searching of all of the weblogs templates
There are four kinds of templates in Movable Type each distinct from the other mainly by their output and use within the system.
The defining characteristic of Index Templates is that they produce a single page. The default template set includes a number of these types of templates including the weblogs main index, RSS/Atom feeds, and a stylesheet. In addition, you can create as many other index templates as you wish, specifying the exact location to which they should be published.
Although they can be used for many different purposes, most of the default index templates are used in presenting different views of the weblogs recent entries either in number, sort order or criteria, or having like attributes. For example, in addition to the main index, Master Archive Index, RSS and Atom feeds, you could offer:
Alternate formats: The same content on the main index in alternate formats like PDF or WordXML format or a stripped down page compatible for mobile-devices.
Different volume and content: A larger list of your recent entries but with only excerpts
Similar attributes: A list of your recent entries with a particular attribute like a single author, category or tag or even only those with recent comments.
Sorting: A list of your recent entries sorted by author, category or other attributes.
A combination of all: A list of the this years entries by a particular author and containing a particular entry tag sorted chronologically by date in plain text format.
Well discuss the methods by which all of these options are made possible when we look at the content of the templates themselves.
As noted before, Movable Type currently supports five archive types:
Monthly, Category and Individual archives are enabled in the system by default.
A number of pages are produced and updated automatically by the system for each archive type that is enabled. For example, the category archives consist of a single page for each category that has at least one entry assigned to it. Each of these pages contains all entries that are assigned to their respective categories. When a new entry is assigned to a category (or an old entry is newly assigned to it), that categorys archive page is updated with the new content.
The monthly archives comprise a single page for each month in which entries were posted containing all of the entries from the month in context and are updated in the same fashion as above. The same also holds for Daily and Weekly archives but for their respective timeframes.
Together the category- and date-based archives serve as historical repositories of entries grouped by topic or period of time in which they were posted.
The individual archives, on the other hand, are literally just a smaller grouping: one page per entry. Because of its focus it is, from the readers point of view, the entry. Hence, the URL to an entry archive page is referred to as its permalink and this page contains all feedback functionality and previously posted feedback for the entry.
While Index templates allow you to publish single pages containing groupings of entries matching a specified set of criteria, it would be burdensome to manually create a page for each new category or new month, or worse, a single page for each entry.
Movable Type automates this process through its archive publishing functionality. The application currently supports the publishing of five archive types. These archive types are produced by three different templates:
Individual entry archive template
Date-based archive template
Category archive template
These three templates are different from each other in that they contain layouts and unique features that are specifically designed for their respective archive types. They are the default templates in use by default archive maps. New archive templates can be created and used in place of, or alongside of the ones provided here.
Unlike Index and Archive templates, system templates are special in that they are used by the system in creating pages which serve as a response to particular functionality. These templates and their functions are listed below:
Comment Preview Template: Controls the display of the comment preview page.
Search Results Template: This template controls the display of the results page from the weblogs search interface when only one weblog is searched.
Comment Pending Template: Controls the page shown to a commenter when their comment is not published immediately. This happens when it has been moderated or flagged as junk.
Comment Error Template: Controls the page shown to the commenter when their comment submission is invalid (e.g. missing required email address, blank comment body, etc)
Uploaded Image Popup Template: Controls the display of the popup image page created by the upload image functionality if the author chose to use a popup window.
Dynamic Pages Error Template: This controls the display of the error page that is served when an error (e.g. file not found) is encountered under dynamic publishing.
Because the system templates are required in providing certain functionality, they can not be replaced and new ones cannot be created. Also note, the system templates are always rendered dynamically by a Movable Type CGI script regardless of your publishing settings. They are never statically published and do not use the Smarty/PHP-based dynamic engine.
Template Modules are user-defined sub-templates that contain bits of template tags, text, and other markup that can be arbitrarily included in any other template. This allows you to keep all commonly used code in one place so modifications can be made once from one place. They are also very useful for holding large or complicated blocks of code that rarely need editing in order to make the templates themselves simpler.
As we mentioned at the beginning of this section, template tags are placeholders for variable content in the Movable Type system. During the publishing process each template tag is responsible for printing out a particular piece of information. In addition, template tags are contextual, meaning that the information that they print out is tightly bound to the placement of the tag itself.
This section will cover the basics of the template tag model. All Movable Type and Movable Type Enterprise template tags are listed and described in full in our online documentation at http://www.sixapart.com/movabletype/docs.
Below we will cover the three classes of template tags (Variable, Container and Conditional) and help you understand how they are used with respect to syntax and context.
Variable tags are simple placeholders that represent a single piece of content like the name of the weblog or the author of a particular entry. For example:
Container tags get their name because they contain other tags and text and are comprised of both start and end tags (sometimes referred to as a tagset). Container tags often provide a list of things to iterate over and the contents inside of such a tag would be evaluated repeatedly. For instance:
In the example above, MTEntries is the container tag and it iteratively lists entries. For each entry, the variable tags inside of it will output the title of the entry, its author and the date on which it was published.
A third type of template tag, called a conditional tag, is a special form of container tag that does not iterate, but simply outputs its contents if and only if the particular conditional statement it represents is true.
Comments are moderated.
In the example above, the text Comments are moderated will be printed if comments on the weblog are moderated.
Conditional tags can be easily recognized because their names always start with MTIf.
For those who are familiar with HTML and XML, Movable Type template tags will seem quite familiar. All template tags are enclosed within less-than and greater-than signs, sometimes referred to as angle brackets. Container end tags have a forward slash that is located after the less-than symbol, but before the tag name.
All template tag names are prefixed with "MT," to separate template tags from other markup tags. To further separate them, an optional dollar sign inside the template tag angle brackets can be added. Here is an example of a template tag:
While the dollar signs are optional, it is highly recommended that they be used on all variable tags to differentiate them from container, conditional and even HTML tags.
This convention is used throughout the default templates and in this documentation.
Some template tags can take attributes that modify the standard behavior of a tag. An attribute is another syntactic feature of MT tags that will be familiar to those that have previously worked with HTML and XML. Attributes are key/value pairs in the angle brackets that follow the tag name and are separated by spaces. Values are always enclosed in double or single quotes. For instance:
In this example lastn is an attribute of the container tag MTEntries with a value of 40. The lastn modifies the behaviour of MTEntries by listing the last 40 entries instead of the default, as configured in the weblog's display settings.
Many template tags have optional attributes and some even have required attributes, all of which can be found in
Additionally, Movable Type provides a set of global filter attributes that can be used on all tags which output content. These global attributes can be found in.
Its necessary to have a basic understanding of MT tag types and their functions in the template engine in order to understand what we mean by tag context. Tag context is an extremely important concept which provides the foundation for the way in which the publishing system works.
Context refers to the interrelated conditions of a tag's position and usage within the template and relationship to other tags surrounding it. The context of a tag defines its behavior, state, and even purpose during the processing of a template. Take this MT template markup for example:
The first occurrence of MTEntryTitle is said to be in the context of MTEntries. As previously discussed MTEntries represents a list of entries that the template engine will loop through, outputting the title with each pass. The second occurrence in this example will generate an error because it is out of the context of MTEntries; the template engine does not know what entry to use to display the title.
The example used above is an example of explicit context. A container tag, in this case MTEntries, is explicitly creating an entry context for all of the content it contains. But MTEntries also must have a context in order to know which entries to list. This is called an implicit context and is provided by both the template containing the tag, the weblog itself and even the system as a whole.
So, for example, while the MTEntries container tag will iterate over the most recent entries on a weblog in the main index template, it provides a list of all entries in a category on a category archive page. Of course, the same tag in the same templates on another weblog would list entirely different entries using that weblog as the source.
Each of these contexts, implicit and explicit, cascade down and combine to form the final context used to evaluate the variable tags which output weblog data. This contextual modification is important because it allows you in almost every case to use the same exact code in different templates without having to worry about including extra instructions for the system about what to output.
When installed, Movable Type has a default look and feel already defined through a series of templates as described in the previous section. Each template serves a different purpose, giving your blog a look, structure, and functionality. However, you may wish to modify some or all aspects of your blog to better suit your needs. To do so, you will need to edit your blogs templates or create new, custom templates for use on your site.
1. In the template listing screen, click the tab corresponding to the type of template you wish to edit or create.
2. If you wish to edit an existing template, locate it within the template listing table and click on the templates title. This will open the template editing screen for that template.
3. If you wish to create a new template, click the Create New Template link found above the template listing table. This will open the template editing screen corresponding to the type of template listing table you are viewing.
4. Edit the template body, corresponding fields and template build options as desired.
5. When finished, scroll to the bottom of the screen to click the Save or Save and rebuild button to save and implement your changes.
If youre familiar with HTML and XML, understanding and editing existing Movable Type templates should be easy. Depending on the particular template type you wish to edit, as well as the aspects of a template you wish to edit, you will need to reference a listing of MT Tags as well. You can find a listing of these tags and their corresponding function and output in our online documentation at http://www.sixapart.com/movabletype/docs/
Besides having some experience with HTML and XML, you should also become familiar with the basic components of a Movable Type template editing screen.
Depending on the type of template you are editing or creating, the template editor will contain many or all of the elements listed below:
Template Name: This is the templates display name as it appears in the template listing table, for example.
Output File: This is the actual filename where the output of the template will be stored. The output file only applies to index templates. It can be either a path (eg. file.html) that is relative to your Local Site Path, or a full path from the root of the local filesystem (eg. /full/path/to/file.html).
Link this template to a file: This optional field allows you to link your template to an external file, as some users will find it easier to edit the template layouts in a text editor or web page design GUI like Adobe Go Live instead of through the Movable Type browser interface. This allows you to edit your templates while keeping the copy that is inside Movable Type synchronized with the external file.
Template Body: This field makes up the body of your template and contains both MT template tags and other markup such as HTML or XML.
Build Options: Here you can opt to force rebuilding of the template whenever index templates are rebuilt, or, depending on your publishing settings, you can opt to build the template dynamically.
Save Options: Depending on your publishing settings and template type, you can either Save your changes to your template, or Save and Rebuild with a single click.
Edit the desired template layout in a text editor like BBEdit or a web page editor like Adobe Go Live instead of the Template Body field in the template editing screen and save it to your hard drive.
Open the template editing screen for the template type you wish to create or edit.
In the field labeled "Link this template to a file", enter either a full path to your external file, or a path relative to the Local Site Path. To avoid the potential of overwriting Movable Type program files and corrupting the system, the file extension for the external file cannot be .cgi, .pm, .pl, or .cfg.
Click the Save or Save and Rebuild button at the bottom of the template editing screen. This will immediately link the template and the specified file.
NOTE: You can link all of the source weblog's templates to file thereby synchronizing templates across multiple weblogs. This creates external files of all the templates you want to share. Link the other weblogs templates to the files created by the first one and upon rebuilding those weblogs, they will now have the same templates.
There are infinite ways in which you can customize and use templates and tags to give your blog a custom look and feel. Outlined below are procedures for a few common customizations.
If youre new to the creation and editing of Movable Type templates, the best way to experiment with the effects of various tags and other manipulations is to simply copy the contents of a standard archive template into a new template editing screen, modify and save it as you wish, and map it to the desired archive type. To further experiment with customizing your MT templates, reference the listing of MT Tags in the appendix to see how these tags might help you accomplish your design and functionality goals.
1. While Movable Type will process and interpolate Movable Type template tags inserted into your templates, the remaining content can be any text or markup you choose. In fact, a template need not contain any Movable Type template tags at all. To publish an existing HTML page through Movable Type, open up the HTML page in your browser.
2. View the source of the page by right clicking on the page (Control-click on a Mac) and selecting View Source.
3. Select the entire page (Control-A on Windows, Command-A on a Mac) and copy (Control/Command-C)
4. In the template listing screen, make sure you are on the Indexes tab.
5. Create a new index template by clicking the Create New Template link found above the template listing table.
6. Give the template a name that best describes the page
7. In the Output file field, you can enter the filename and/or path of the existing file if you wish to overwrite it or a different one if you wish to create a new, duplicated page.
NOTE: The output file field assumes that you are publishing underneath the weblogs Site Root so you only need to put the filename (e.g. team.html) and optionally append a subdirectory path in front of it (e.g. about/team.html), but you can also enter an absolute path like: /var/www/html/about/team.html
8. Paste the page contents into the Template Body field (Control or Command-V)
9. Save the template and Rebuild the page.
Archive Templates allows for pages to be created for different views of the weblog's entries. MT supports a few date-based archives -- daily, weekly, and monthly -- in addition to individual entry and category archives. These templates are used to create multiple pages, one for each "unit" (time-period, entry or category) of the archive.
The implied context for these Archive Templates (Date Based
and Category Based) is the current weblog and a selection of entries for a
particular time-period or category. Unless instructed differently through its
MTEntries tagset will list all entries for the
category in context.
Because of the adaptive nature of the
tag we can reuse the same markup in mutiple templates. Reusing an entry's
layout is entirely at your discretion. MT allows you to create completely
unique layouts for each archive if you so choose.
Tags prefixed with MTArchive, such as
from this example, are a class of tags for displaying information about
archives. These tags used can be used in any Archive Template or in the context
Individual Entry Archive Templates have an implied context
of one particular entry within the current weblog. Unlike date-based and
category-based archives, a
MTEntries tag is not needed. While
entirely valid when used in an Individual Archive Template, using them in that
situation does not make a lot of sense. The MTArchive tags, if they display
anything at all, will display information that can be retrieved using
Additionally, you can use a
MTEntries tag to
display information about the entries in a particular archive. For example:
This will display a link to the archive page, followed by a list of entry titles.
This tag takes two attributes
archive_type that specify the type of archive to list with values
of "Individual," "Daily," "Weekly" or "Monthly."
lastn limits the number of archives that will be listed.
archive_type is optional. If
omitted, the listing will use the Preferred Archive Type setting. This
attribute is useful when you have selected more than one value for the weblog's
Archive Type, and you wish to list something other than your Preferred Archive
Type. For example, if you have chosen to keep both
archives, and your Preferred Archive Type is
Individual, you can
Daily archives using this tagset:
lastn can be used to limit the number of
archives in the list. For example, if you have 10 months worth of archives in
your weblog, and you only wish to list the last five monthly archives you could
use this tagset:
If you are rendering your templates statically, Movable Types publishing performance (i.e. Rebuilding) will degrade over time as the amount of content your are producing increases. However, there are a number of ways to keep your publishing performance well within acceptable limits.
SQL-based databases: Because most web hosts offer ancient versions of BerkeleyDB, publishing performance (and all system performance) can be greatly degraded. Using a SQL-based database will drastically improve performance. We recommend MySQL for Movable Type and Oracle 10g for Movable Type Enterprise.
Consolidation of published content: This is one of the most important aspects of publishing optimization. See the following section on Eliminating Redundant Publishing for more.
Dynamic publishing: Dynamic publishing makes an immediate impact on rebuilding times experienced by Movable Type authors by spreading out the burden of rebuilding onto each site visitor in much smaller amounts. Dynamic publishing of archive files is a wonderful choice for small, low- to medium- traffic blogs. If you have a high-traffic blog, however, dynamic publishing is not recommended.
Removed unused plugins: Each plugin used incrementally increases the load on the system. If you have a very large number of plugins or plugins which are poorly coded, this can greatly impact your publishing speed. Remove or disable any plugins you are not using and always update to the latest available versions.
More details on these and other publishing optimization tips can be found at http://www.sixapart.com/pronet/articles/how_to_speed_up.html
If you are already using a robust database such as MySQL or Oracle 10g, the best thing you can do to improve your publishing performance is to eliminate redundant processing of template tags in your templates. For example, inserting the template code to create a tag cloud on every page of your weblog causes Movable Type to process that code each time. By consolidating that code into one template and including the processed output of that code into each template, you not only make it easier to change but also greatly reduce the work that Movable Type must do to publish your weblog.
Two popular methods for including single-sourced content are through the use of template modules or server-based include files.
Template modules are simple containers for repeated content or complex code which can be included into other templates on the weblog. Instead of including the code to create a tag cloud from the example above into each page, you could create a template module of the code (named, for example, Tag Cloud) which you can include into each template using the MTInclude tag:
<$MTInclude module=Tag cloud$>
Template modules can contain anything including MT template tags, static text and HTML markup, so they are also useful for things like a common header or footer used on your weblog.
All template tags included in a template module are evaluated in the context of where the MTInclude tag is placed. For example, if you placed the following code into a template module called Entry list:
and included it into your main index, category archive and monthly archive like so:
<$MTInclude module=Entry list$>
it would print out a different list of entries for each of those template, just as if you had included the template module code on each of the individual templates.
The other method for optimizing publishing performance is through the use of server-based include files. This can be done via server side includes or via PHP using the include() function. The benefit of using server-base include methods is that Movable Type evaluates the template module code only once and that the same results are included into any published file.
This is useful is you wish to avoid the contextual evaluation of the template code described above.
Including content via PHP:
Including content via Apache Server-side includes:
You can read more about these functions from the PHP and Apache sites:
PHP include function: http://us3.php.net/include/
Apache server-side includes: http://httpd.apache.org/docs/1.3/howto/ssi.html