Step 3. Create your Template
The templating language used to generate the HTML of the blogs and web sites published by Movable Type is the exact same language used for rendering pages within the application. This templating language provides a rich set of template tags that abstracts developers and designers away from the core application using a customizable, but still rigid set of semantics that make Movable Type more secure and less error prone. These tags also ensure thats any new page that is created using this language will work equally well on any operating system and using almost any database.
Users familiar with Smarty, JSP, ASP, PHP or any other popular web based templating framework should feel at home using Movable Type’s templating language as it allows developers to easily interweave the programmatic display of data within HTML.
Here is the ubiquitous “Hello World” example for a Movable Type application template:
<mt:setvarblock name="page_title">This is a page title</mt:setvarblock> <mt:include name="include/header.tmpl"> <p>Hello World!</p> <mt:include name="include/footer.tmpl">
More powerful than your average Hello World example, this will actually produce a screen that looks and behaves like a natural extension of the core Movable Type user interface - thanks to the inclusion of the global header and footer templates.
Where to place your template
If you remember from the Movable Type Developer Guide, every Movable Type plugin should adhere to a simple directory structure. In that directory structure is a
tmpl directory that contains all of the templates for your plugin or application, for example:
Movable Type will automatically search for templates in this directory. This directory can also contain subdirectories. Say for example you wanted to maintain a hierarchical set of templates like so:
You could then reference that template using a relative path like so:
my $tmpl = $plugin->load_tmpl('screen_foo/main.tmpl');
Movable Type itself utilizes two includes that give every screen in Movable Type a consistent look and feel. These includes are
include/footer.tmpl. In subsequent sections we will discuss ways in which you can influence the structure and contents of your plugin’s header and footer without having to resort to hacking these template manually.