Est. 1999 Beginner

Template Toolkit

A powerful, presentation-focused template processing system for Perl that enforces a clean separation between application logic and output, widely used to build web sites, generate documents, and produce code.

Created by Andy Wardley

Paradigm Template processing; declarative presentation with an embedded mini-language
Typing Dynamic; values are Perl scalars, lists, hashes, and objects exposed through a uniform dotted-access syntax
First Appeared 1999 (evolved from the 1996 Text::MetaText prototype)
Latest Version Template Toolkit 3.106 (released May 2026)

The Template Toolkit (commonly abbreviated TT or TT2) is a mature, presentation-oriented template processing system written in Perl. Rather than embedding a full programming language inside markup, it provides a small, purpose-built directive language for turning data into text — most famously HTML for web sites, but equally well configuration files, email, LaTeX, PDF source, SQL, or program source code. Its guiding idea is a strict separation between the logic of an application (kept in Perl) and the presentation of its output (kept in templates), a discipline that made it a cornerstone of Perl web development for well over two decades.

History & Origins

The Template Toolkit was created by Andy Wardley. Its lineage begins in 1996 with Text::MetaText, a Perl module Wardley wrote for processing text with embedded directives. Text::MetaText served as the conceptual prototype: it explored the idea of a directive-driven text preprocessor, but the design that would become the Template Toolkit was a more ambitious reworking of those ideas.

The first release of the Template Toolkit proper appeared in 1999 on CPAN, the Comprehensive Perl Archive Network. Two years later, in 2001, Wardley released version 2.00 — the version universally known as TT2. TT2 was a substantial rewrite and quickly became the definitive, long-lived incarnation of the toolkit; for most of its history, “the Template Toolkit” and “TT2” were effectively synonyms.

In 2003, O’Reilly published Perl Template Toolkit by Darren Chamberlain, Dave Cross, and Andy Wardley — a book affectionately known as the “Badger Book” after its cover animal — which cemented TT’s place in the Perl ecosystem and served as the canonical reference for years.

An ambitious TT3 rewrite was begun but ultimately set aside. Rather than abandon the version number, the maintained TT2 codebase was eventually released as version 3.0 in late 2019, modernizing packaging and internals while remaining backward compatible with the enormous body of existing TT2 templates. Maintenance has continued steadily since; the toolkit reached version 3.106 in May 2026.

Design Philosophy

The Template Toolkit’s defining choice is what it leaves out. Competing Perl systems of its era — such as HTML::Mason and Text::Template — let authors embed arbitrary Perl directly in templates. TT deliberately does not. Instead it offers a compact mini-language of directives, expressive enough for presentation tasks (looping, conditionals, formatting, including other templates) but intentionally too limited to encourage business logic from creeping into the view.

This reflects a Model–View separation philosophy:

  • Application logic lives in Perl modules and is unit-testable in isolation.
  • Presentation logic lives in templates that a designer — not necessarily a Perl programmer — can safely edit.
  • The interface between them is a set of variables (Perl scalars, lists, hashes, and objects) passed into the template’s “stash.”

Because complex operations are pushed back into Perl, templates stay readable, and the same data can be rendered through many different templates.

Key Features

TT directives are written between configurable tags — by default [% ... %]:

[% INCLUDE header.tt title = "Welcome" %]

<ul>
[% FOREACH user IN users %]
  <li>[% user.name | html %] — [% user.email %]</li>
[% END %]
</ul>

[% IF users.size == 0 %]
  <p>No users found.</p>
[% END %]

[% INCLUDE footer.tt %]

Notable capabilities include:

  • Uniform dotted access. user.name works whether user is a hash, an object with a name method, or a list index — the same . syntax reaches into any data structure, hiding Perl’s sigil distinctions from template authors.
  • Directives for flow and reuse. FOREACH, IF/ELSIF/UNLESS, WHILE, SWITCH, plus INCLUDE, PROCESS, WRAPPER, BLOCK, and MACRO for composing templates and defining reusable fragments.
  • Filters and virtual methods. Pipe values through filters such as | html, | uri, | upper, or | format, and call built-in “virtual methods” on lists and hashes (for example list.size, list.sort, hash.keys).
  • Plugins. A plugin system exposes CPAN functionality — dates, tables, data feeds, and more — to templates in a controlled way.
  • Command-line tools. The bundled tpage processes a single template, and ttree processes whole directory trees of templates, making TT useful for static site and document generation entirely outside a web server.
  • Optional C acceleration. A stash implementation written in C is available to speed up variable access in performance-sensitive deployments.

Evolution

The arc from Text::MetaText (1996) to the first release (1999) to TT2 (2001) established the toolkit’s core, and TT2 proved remarkably stable — a testament to a design that got the fundamentals right early. Much of the toolkit’s later “evolution” happened in its ecosystem rather than its core: framework view classes (notably Catalyst::View::TT), a rich collection of plugins, and adoption by large applications like Bugzilla.

The most significant version event came in 2019, when the experimental TT3 effort was retired and the maintained line was released as version 3, focused on modernizing the distribution rather than breaking template syntax. This backward-compatibility-first approach means templates written for TT2 in the early 2000s generally still run today.

Current Relevance

The Template Toolkit remains one of the most widely used templating systems in the Perl world and is still actively maintained, with releases continuing into 2026. It is a natural choice wherever Perl is already in use — web applications, internal tooling, and document/code generation pipelines — and its clean separation of concerns keeps it relevant even as newer templating fashions come and go. Its influence is also visible in compatible re-implementations such as Template::Alloy, which aim to run existing TT templates.

Its relevance today is strongest in three areas:

  • Legacy and long-lived systems — large codebases like Bugzilla that standardized on TT and continue to depend on it.
  • Perl web frameworks — where TT remains a common, well-supported view layer.
  • Non-web text generation — using tpage/ttree to build configuration, documents, and code from templates.

Why It Matters

The Template Toolkit is a case study in the value of deliberate constraint. By refusing to let a full programming language leak into templates, it pushed the Perl community toward cleaner architecture and made templates something a non-programmer could safely maintain. That model — a small, safe presentation language backed by a powerful host language — anticipated the design of many later “logic-less” and logic-light templating systems across other ecosystems. For a generation of Perl developers building the dynamic web, TT was the tool that made separating structure from content not just possible, but pleasant.

Sources

Timeline

1996
Andy Wardley releases Text::MetaText, a Perl text-processing module that acts as the conceptual prototype for what would become the Template Toolkit
1999
The first version of the Template Toolkit proper is released on CPAN, reworking the earlier ideas into a dedicated template processing engine
2001
Template Toolkit 2.00 (widely known as TT2) is released — a substantial rewrite that became the long-lived, dominant version of the toolkit
2003
O'Reilly publishes "Perl Template Toolkit" (the "Badger Book") by Darren Chamberlain, Dave Cross, and Andy Wardley, giving the project a definitive reference text
2005
The Catalyst web framework ships Catalyst::View::TT, making the Template Toolkit a common default view layer for a generation of Perl web applications
2019
After an experimental TT3 rewrite was set aside, the maintained TT2 codebase is released as version 3.0, modernizing the distribution while preserving backward compatibility
2026
Version 3.106 is released (May 2026), continuing steady maintenance and incremental improvements more than two decades after TT2

Notable Uses & Legacy

Bugzilla

Mozilla's long-running bug-tracking system uses the Template Toolkit for its entire user interface; its template/ directory holds the shipped TT templates and supports localization and customization without touching Perl code.

Catalyst MVC Framework

The Catalyst web framework provides Catalyst::View::TT, which renders the request stash through the Template Toolkit, making TT one of the standard view layers for Perl web applications.

Movable Type

Six Apart's Movable Type publishing platform is, according to community references such as Wikipedia's list of Template Toolkit users, reported to have used the Template Toolkit as part of its templating and page-generation machinery for blogs and content sites.

Webmin

The Webmin web-based system administration interface is reportedly among the Perl applications that have drawn on the Template Toolkit for generating portions of their HTML output, though much of Webmin's interface is generated through its own Perl/CGI theme functions.

Static site and document generation

Beyond HTML, developers use TT with the bundled tpage and ttree command-line tools to generate configuration files, LaTeX and PDF source, SQL, and source code from data-driven templates.

Language Influence

Influenced By

Perl Text::MetaText

Influenced

Template::Alloy

Running Today

Run examples using the official Docker image:

docker pull perl:latest

Example usage:

docker run --rm -v $(pwd):/app -w /app perl:latest sh -c "cpanm -qn Template && tpage hello.tt"
Last updated: