GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Inline::TT(3) User Contributed Perl Documentation Inline::TT(3)

Inline::TT - Provides inline support for template toolkit 2.x

Inline::TT provides Inline support for Template Toolkit versions 2.x.

    use Inline TT => 'DATA';

    print hello( { name => 'Rob' } ), "\n";

    print goodbye( { name => 'Rob' } ), "\n";

    __DATA__
    __TT__
    [% BLOCK hello %]
    <H1> Hello [% name %], how are you? </H1>
    [% END %]
    [% BLOCK goodbye %]
    <H1> Goodbye [% name %], have a nice day. </H1>
    [% END %]

Alternatively:

    use Inline TT => << EO_TEMPLATE
    [% BLOCK hello %]
    <H1> Hello [% name %], how are you? </H1>
    [% END %]
    EO_TEMPLATE

    print hello( { name => 'Rob' } ), "\n";

See the Inline perldoc for even more ways to reference the inline source.

"Inline::TT" provides Inline access to version 2.0 and higher of the Template Toolkit. This allows you to house your templates inside the source code file, while retaining the ability to cache compiled templates on the disk (via Inline's caching mechanism).

The names of the blocks in the template are exported as functions. Call these with a reference to a hash of values, which will be used for interpolation in the templates. This hash reference is the same as the second argument to the "process" method of any Template object. The output from template toolkit will be returned to you as a single string. Note that leading and trailing spaces are trimmed, further the template toolkit options PRE_CHOMP and POST_CHOMP are set. Currently, there is no way to change these behaviors.

You can pass options to Inline::TT. Two of the options are specific to Inline::TT:
TRIM_LEADING_SPACES
Set this to one to remove all leading spaces from the text generated by TT. You should also consider using PRE_CHOMP, if you use PROCESS or INCLUDE directives.
TRIM_TRAILING_SPACES
Set this to one to remove all trailing spaces from the text generated by TT. You should also consider using POST_CHOMP, if you use PROCESS or INCLUDE directives.

These two options work on the final and complete string. They don't remove ANY interior spaces, only the ones at the beginning and end of the whole string.

The rest of the options are passed without comment or validation directly to TT.

Note passing options can be done at compile time or at run time. To do it at run time, use Inline->bind. See t/06_options for examples of passing options at run time and at compile time.

Some people (including me at times) prefer to separate formatting from code, but not by much. For example, we don't like to have xml embedded inside Perl, but we don't want to have to hunt on the disk for a template whose name is likely hidden in a config file (a config file whose name we may not even remember). By using Inline::TT, we can store the templates in the program, but away from the code that supplies their data. Yet, because of the wonders of Inline, we still benefit from disk based caching of templates. (For details about caching see the Inline documentation, search for _Inline.)

The names you used for the BLOCKs in the template, are exported into your calling package as sub names.

Only things in BLOCKs are accessible through Inline::TT.

This module is one of many in the Inline:: family. You must have Inline version 0.42 or higher to use this module. See the Inline documenation for how to control the location of files it caches.

Phil Crow, <phil@localdomain>

Copyright (C) 2005 by Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.

2006-02-04 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.