MT::Template - Movable Type template record
use MT::Template;
my $tmpl = MT::Template->load($tmpl_id);
defined(my $html = $tmpl->build($ctx))
or die $tmpl->errstr;
$tmpl->name('New Template name');
$tmpl->save
or die $tmpl->errstr;
An MT::Template object represents a template in the Movable Type system. It contains the actual template body, along with metadata used for keeping the template in sync with a linked file, etc. It also contains the functionality necessary to build an output file from a generic template.
Linking a template to an external file means that any updates to the template through the Movable Type CMS will be synced automatically to the file on disk, and vice versa. This allows authors to edit their templates in an external editor that supports FTP, which is preferable for users who do not like editing in textareas.
As a subclass of MT::Object, MT::Template inherits all of the data-management and -storage methods from that class; thus you should look at the MT::Object documentation for details about creating a new object, loading an existing object, saving an object, etc.
The following methods are unique to the MT::Template interface:
Given a context $ctx (an MT::Template::Context object) and an optional set of conditions \%cond, builds a template into its output form. The template is first parsed into a list of tokens, then is interpreted/executed to generate the final output.
If specified, \%cond should be a reference to a hash with MT tag names
(without the leading MT) as the keys, and boolean flags as the values--the
flags specify whether the template interpreter should include any
conditional containers found in the template body.
Returns the output as a scalar string, undef on error. Because the empty
string '' and the value 0 are both valid return values for this method,
you should check specifically for undef:
defined(my $html = $tmpl->build($ctx))
or die $tmpl->errstr;
The MT::Template object holds the following pieces of data. These fields can be accessed and set using the standard data access methods described in the MT::Object documentation.
<MTInclude>.
index,
an Index Template; archive, an Archive Template; category, also an
Archive Template; individual, also an Archive Template; comments, a
Comment Listing Template; comment_preview, a Comment Preview Template;
comment_error, a Comment Error Template; popup_image, an Uploaded Image
Popup Template; or custom, a Template Module.
If the template is linked to an external file, the body of the template is automatically synced between this data field and the external file.
In addition to numeric ID lookup, you can look up or sort records by any combination of the following fields. See the load documentation in MT::Object for more information.
Please see the MT manpage for author, copyright, and license information.