Publishing Custom Pages with Movable Type

MT has had the ability to output any content in a template since version 1.0 in 2001, however it doesn't have the "push button" simplicity of Wordpress' Pages feature. For those of you unfamiliar with Wordpress, its Pages feature allows you to create individual static pages (index pages in MT) with the simplicity of the entry screen, i.e. you don't need to worry about the styling or markup - just type out the content and voila, you're done.

This tutorial describes the process to simplify the process of creating standalone pages so that, in essence, you simply need to type out your content. This is useful for using Movable Type as a powerful general content management system.

There are 3 main steps:

  • Separate your page content from the general layout.
  • Create separate index templates to store your header and footer
  • Create an index template to store your content

The first thing you need to do is separate the page's content from the styling and general markup. Open your Main Index Template and select everything from the top of the template to right before the opening <MTEntries> container tag. Copy the selected code into a new index template, name it "Header", and give it an appropriate output file, e.g. "header.html". Next, go back to the Main Index Template, select everything after the closing </MTEntries> container tag and copy that into a new index template called Footer, again with an appropriate output file e.g. "footer.html."

These two files can now be included everytime you want to create a new page, saving you the time it would take to re-create all the general markup like the DockType, stylesheet etc. When creating a new page, you'll want to first include the header file (either using a PHP/SSI include or using MTInclude), then have your content, and finally include the footer file.

You'll need to change certain elements in the header and footer files if you want these sections displayed differently for different pages. You can refer to this tutorial on how to do that but I will give an example here. One thing that will change from page to page is the Title of the page, hence in the header file, replace the title tag with this

<title><MTBlogName> - <?php echo $title; ?></title>

and on every page, you will now need to set the value of $title to be the title you would like for the page, like so (ensure this is before including the header file)

<?php $title = "About Page"; ?>

As described in this tutorial, you can use the MTSetVar/GetVar tags or PHP Variables for other types of conditional display.

If you would like to further simplify the process of creating pages, you can hack edit_template.tmpl so that the header and footer files are automatically included as is the $title variable. Open edit_template.tmpl and between the <textarea> tags, add something like the following (I've used PHP includes, you can replace them with includes of your choice).

<?php $title = "Page Title"; include('<MTBlogURL>header.html'); ?>
<?php include('<MTBlogURL>footer.html'); ?>

What this does is automatically include the header and footer files when you create a new index template.

You can make the process of creating new pages even easier by implementing Quicktags or installing a text filter like Markdown that provides template tags for you to use.

Movable Type's powerful templating system allows you to create any number of custom index templates. Focusing this power on specific standalone pages is easiest if you make smart use of reusing page elements either through the of external includes or the platform's built-in ability to easily reuse page elements.


Chad S said:
on Aug 4, 2005 8:40 PM | Reply

Thanks Arvind. This is an interesting way of publishing custom pages. I usually set up a custom pages blog for each MT installation. It's not elegant, but it works. One shortcoming with the method detailed above, is that it seems that content on templates does not get indexed for MT site search. This means that custom pages won't appear in site search results. Is there a way to have template content included in search results?

Jenna Pfister said:
on Aug 5, 2005 5:08 AM | Reply

Great write-up! I, too, use a similar templating system. It makes custom pages really easy to implement.

Cameron Stotz said:
on Oct 14, 2006 3:44 AM | Reply

That's awesome, and just what I'm looking for. In MT, customizing hits a brick wall when you start dealing with searches and search results (mainly). Let's see if this helps. THANKS.

SV said:
on Aug 22, 2007 9:46 PM | Reply

FYI, error on tutorial link above

Parse error: syntax error, unexpected '<' in /home/movalog/public_html/blog/a/variables-and-conditional-display/index.php on line 149

Arvind Satyanarayan replied to SV's comment:
on Aug 23, 2007 7:28 PM | Reply

Hi Thanks for the heads up, I've fixed the errors :)