rendering1Add my vote for this tag skin1Add my vote for this tag template_system1Add my vote for this tag create new tag
, view all tags
Warning: Alpha Code, interfaces may change radically. Do not use in production code.

Template Toolkit Plugin

This is a rather slim glue to Andy Wardley's Template Toolkit (see http://www.template-toolkit.org/ or TWiki:Codev.TemplateToolkit for more, though the latter is pretty stale).

I myself have here and then argued that TT is too heavyweight for use as a template system for TWiki, but this does only prevent using TT as the only template system for TWiki.

If, on the other hand, you do have TT installed anyway, and especially if you have it running in a mod_perl environment where module compilation time is no longer an issue, then you might want to share your TT blocks or layouts with TWiki.

The implementation as a plugin does not allow to install TT as a drop-in replacement for TWiki's own templating system. But I think that for first experiments it is possible to emulate that: Use very slim TWiki templates to get TWiki's template system out of the way, and run your topics through TT instead.

To be honest, I am using this plugin as both a first step to evaluate TT as a TWiki template machine, and as a real-life hands-on example for BenchmarkContrib to play with.

Syntax Rules

The plugin has just one TWiki tag in the TWiki sense:

  • Syntax example: %TEMPLATETOOLKIT{"on" WRAPPER="myTTtemplate.tt2"}%
  • If present in a topic with a value of "on", the whole topic will be processed by TT.
  • A configuration variable named $TWiki::cfg{Plugins}{TemplateToolkitPlugin}{UseTT} can be used to set a site-wide default
  • Supported Parameters:
    Parameter: Description: Default:
    "on" / "off" Switch to control TT usage for the current topic. A value "on" or "1" will activate TT processing for the current topic, every other value will disable it. To retain the configuration setting, don't specify this parameter. Config variable {UseTT}
    WRAPPER="tt_template" The TT wrapper template into which the topic will be embedded. The wrapper must explicitly include the topic content, which is available as a TT variable [% content %]. no wrapper

Configuration Variables

Not fully documented, until I figure out how http://twiki.org/cgi-bin/configure will pick up plugin configuration vars.

All configuration variables for this plugin are collected under $TWiki::cfg{Plugins}{TemplateToolkitPlugin}.

Configuration Variable Description
{UseTT} Sitewide default for TT usage. Can be overridden in a topic with the %TEMPLATETOOLKIT{...}% tag.
{TToptions} Hash reference passed as \%config parameter to Template->new(). Refer to the TT documentation for details.
Per default, the current topic's attachment directory is used as INCLUDE_PATH, and the START_TAG option is basically the familiar [%, but adjusted to take care for TWiki forced link/variable combinations.

Notes on Template Toolkit Syntax

If you are familiar with the Template Toolkit, then you surely know that it per default embeds its directives between the delimiters [% and %]. As almost everything in TT this is configurable, but the default delimiters are used quite frequently because they usually don't occur in "normal text". Usually. In TWiki, there is a syntax construction which is quite popular, but makes TT croak: Forced links, with an embedded TWiki variable. Example:

This is a valid TWiki link pointing to TWiki06x00.WebStatistics, but an invalid TT construct [% TWIKIWEB%.%STATISTICSTOPIC %] within an additional set of square brackets.

This plugin tries hard to cope with this, so the above example will work as intended. Some recommendations, just in case:

  • It is good practice to write your TT constructs as [% tt_directive %], i.e. with surrounding spaces around directives. By doing so, you'll make sure to never clash with a possible TWiki variable name %tt_directive%.
  • Separate TT stuff from heavy TWiki lifting or you'll get severe bracketiquotitis.
  • If you want to use different delimiters, define both {TToptions}{START_TAG} and {TToptions}{END_TAG} in $TWiki::cfg{Plugins}{TemplateToolkitPlugin}.
  • When writing TT wrappers for use with this plugin, keep in mind that they are TT-expanded, but not TML-processed.


Per default, TemplateToolkitPlugin ships with a simple TT demo wrapper. To see it in action, prepend a topic with the following line:

%TEMPLATETOOLKIT{"on" WRAPPER="demowrapper.tt2"}%

TT expansion can be controlled by URL parameters as well. If the plugin is installed, you can apply the demonstration wrapper to the current topic by clicking here.

Security Considerations

Unlike in typical TT web applications, in a TWiki many people can edit the templates, and so they can introduce TT directives. To keep your TWiki unharmed, some precautions should be made:

  1. Do not enable EVAL_PERL (it is off per default).
  2. Do not pass critical data structures like the configuration hash as TT variables. Remember that with TT directives it is possible to change data, and to call object methods. With a persistent interpreter like mod_perl, this could lead to a corrupt configuration for subsequent requests.

Future Directions

If time permits, I'll try to:

  • create a TWiki skin and a TT layout in parallel and run benchmarks on both.
  • document (and extend) configuration items
  • Add a TWiki filter for TT templates so that wrappers can use TWiki variables
  • ...

Plugin Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server where TWiki is running.

Like many other TWiki extensions, this module is shipped with a fully automatic installer script written using the BuildContrib.

  • If you have TWiki 4.1 or later, and Perl 5.8, you can install from the configure interface (Go to Plugins->Find More Extensions)
  • If you have a permanent connection to the internet (and Perl 5.8), you are recommended to use the automatic installer script
    • Just download the TemplateToolkitPlugin_installer perl script and run it.
    • If the $TWIKI_PACKAGES environment variable is set to point to a directory, the installer will try to get archives from there. Otherwise it will try to download from twiki.org or cpan.org, as appropriate.
    • (Developers only: the script will look for twikiplugins/TemplateToolkitPlugin/TemplateToolkitPlugin.tgz before downloading from TWiki.org)
  • If you don't have a permanent connection, you can still use the automatic installer, by downloading all required TWiki archives to a local directory.
    • Point the environment variable $TWIKI_PACKAGES to this directory, and the installer script will look there first for required TWiki packages.
      • $TWIKI_PACKAGES is actually a path; you can list several directories separated by :
    • If you are behind a firewall that blocks access to CPAN, you can build a local CPAN mini-mirror, as described at http://twiki.org/cgi-bin/view/Codev/BuildingDakar#CPAN_local_minimirror
  • The installer script will:
    • Automatically resolve dependencies,
    • Copy files into the right places in your local install even if you have renamed data directories,
    • check in new versions of any installed files that have existing RCS histories files in your existing install.
  • If you don't want to use the script, or have problems on your platform (e.g. you don't have Perl 5.8), then you can still install manually:
    1. Download and unpack one of the .zip or .tgz archives to a temporary directory.
    2. Manually copy the contents across to the relevant places in your TWiki installation.
    3. Check in any installed files that have existing ,v files in your existing install (take care not to lock the files when you check in)
    4. Manually edit LocalSite.cfg to set any configuration variables.
    5. Run configure and enable the module, if it is a plugin.
    6. Repeat from step 1 for any missing dependencies.

Plugin Info

Author: TWiki:Main/HaraldJoerg
Copyright ©: 2006, TWiki:Main/HaraldJoerg, All Rights Reserved
License: GPL (GNU General Public License)
TWiki Dependency: $TWiki::Plugins::VERSION 1.1
Template>=2.000Required. Available from CPAN.
Other Dependencies: none
Perl Version: 5.8
Version: 0
Change History:  
21 Sep 2006: Initial version
TWiki:Plugins/Benchmark: unknown
Home: http://TWiki.org/cgi-bin/view/Plugins/TemplateToolkitPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TemplateToolkitPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TemplateToolkitPluginAppraisal

Related Topics: TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory, TWikiPreferences

-- TWiki:Main.HaraldJoerg - 21 Sep 2006

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 TemplateToolkitPlugin.md5 r4 r3 r2 r1 manage 0.2 K 2008-12-12 - 12:40 SopanShewale checksum file , Uploaded as a part of Release Process
Compressed Zip archivetgz TemplateToolkitPlugin.tgz r4 r3 r2 r1 manage 9.3 K 2008-12-12 - 12:40 SopanShewale See TemplateToolkitPlugin for details. Untar and run the installer script, Uploaded as a part of Release Process
Compressed Zip archivezip TemplateToolkitPlugin.zip r4 r3 r2 r1 manage 12.1 K 2008-12-12 - 12:40 SopanShewale See TemplateToolkitPlugin for details. Unzip and run the installer script , Uploaded as a part of Release Process
Unknown file formatEXT TemplateToolkitPlugin_installer r4 r3 r2 r1 manage 3.6 K 2008-12-12 - 12:40 SopanShewale Installer Script, Uploaded as a part of Release Process
Unknown file formattt2 demowrapper.tt2 r1 manage 1.5 K 2006-09-25 - 19:53 HaraldJoerg demowrapper.tt2
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2008-12-12 - SopanShewale
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2016 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.