You are on page 1of 2

Template Toolkit:

1. Use template;

Declare variables next


Generate magic header etc

2. Create template object:


$tt_object = Template ->new(
{
INCLUDE_PATH => #tells where templates are located
[ ‘/export/srv/www/vhosts/main/tt2’ ],
PRE_PROCESS=> ‘header.ex.tt2’,
POST_PROCESS=> ‘footer.ex.tt2’
}
);
$template = ‘first.ex.tt2’; #this is the name of actual external template, the body

3. Pretend to do somme work

$sample=(“Get your data ready”);


%where=(ALL=>’Entire stuff’,
OT=>’wtf’,
BT=>’blah’,
);

4. Get your variables read for binding

$vars = {
tound_string => $sample,
title => ‘This is simpler than i thought’,
contact_email => ‘mailto:email’,
contact_user => ‘user’,
books => \%where,
#keys/values must be singular in association, therefore assigning where hash to books hash
#the \ takes the hash and assigns it where to books as a reference
};

5. Bind and pass flow


$tt_object->process ( $template, $vars )
#process method binds the vars data to the template we previously indicated
or die ( $tt_object->error() );

Templates can call templates


Loop that lets you take data out of the hash and then output it with html using the <option>

[% FOREACH meta IN books.keys.sort %]


<option valoue=”[ % meta %]”>[% books.$meta %] </option>
[% END %]

You might also like