Not a developer? Go to MovableType.com

Documentation

Alternate Application Templates

Developers have a couple of different options available to them for modifying the core user interface of the application without modifying the core application itself. These capabilities are added to allow plugins to take the control they need without requiring users to make changes to the application that might make future upgrades more difficult.

In this document we discuss the use of Alternate Templates (or “alt templates” for short).

alt_tmpl directory

Developers can override the templates used by the application to display its user iterface, without overwriting the templates the application ships with, by placing alternative versions of those templates in the /path/to/mt/alt-tmpl directory. Files placed there should have the same file name as the template they wish to override. For example, let’s suppose we would like to provide an alternative to the Movable Type dashboard. Here are some steps you can follow to make those changes safely without altering the original files:

  1. Make a copy of the dashboard template and place it in the alt-tmpl directory: cp /path/to/mt/tmpl/cms/dashboard.tmpl /path/to/mt/alt-tmpl
  2. Edit the file now located at /path/to/mt/alt-tmpl/dashboard.tmpl

Movable Type will begin using your version of the template as opposed to the version that came with Movable Type by default.

Special Note

There is one limitation to using this method for overloading the Movable Type user interface: only one plugin can override a template in this manner.

Loading Alternate Templates Based upon UserAgent

Every time a page is requested from a Web server, the requesting client transmits information about itself, including the name of the browser making the request, the operating system being used and any additional version information that might be helpful.

The iMT plugin which provides an specially designed user interface for users of Apple’s iPhone makes use of this UserAgent information to modify the search path for templates in real time based upon the client making the request.

Each MT::Plugin and anything that extends the MT::Plugin package can implement an init_request method that will be called each and every time the Movable Type application is accessed. This allows plugins to intercept any request to the application for special handling.

In this case, the init_request method is used to detect if the device accessing Movable Type is an iPhone, and if it is to prepend to the template search path the location of the plugin’s alt templates.

package MT::Plugin::iMT;
use MT 4;
use base qw( MT::Plugin );
my $enabled = 0;
our $VERSION = '1.0';
my $plugin = __PACKAGE__->new({
    name        => "iPhone / iPod touch UI Support",
    # snip
});

sub init_request {
    my $plugin = shift;
    my ($app) = @_;
    $enabled = 0;
    if ($app->isa('MT::App::CMS')) {
        if (my $ua = $ENV{HTTP_USER_AGENT}) {
            if (( $ua =~ m!AppleWebKit/! ) && ( $ua =~ m!Mobile/! )) {
                $enabled = 1;
                # Redirect 'dashboard' or 'default' modes to iphone_main
                $app->mode('iphone_main')
                    if ($app->mode eq 'default') || ($app->mode eq 'dashboard');
                $app->config('AltTemplatePath', $plugin->path . '/tmpl');
            }
        }
    }
}

See Also

Back