Sly
Sly

Reputation: 415

Template::Toolkit variable processing

I'm using TT from perl, and trying to insert into template and process a variable, that itself contains TT directives.

So, in the script I'm writing smth like:

$var{descr} = "[% pid = 1; INSERT plink.par %]";

And then in TT template (which received \%var):

[% BLOCK parsedDescr %]
[% descr %]
[% END %]
<p>[% INCLUDE parsedDescr %]

And I'm expecting pid variable being set to "1", and plink.par file inserted. But instead I get on my html page exactly contents of the variable descr:

[% pid = 1; INSERT plink.par %]

i.e., this variable stays unprocessed by TT.

How do I make TT process it's contents?

Upvotes: 5

Views: 924

Answers (1)

Eugene Yarmash
Eugene Yarmash

Reputation: 149806

You can use the eval filter:

<p>[% descr | eval %]

From the linked manpage:

The eval filter evaluates the block as template text, processing any directives embedded within it. This allows template variables to contain template fragments, or for some method to be provided for returning template fragments from an external source such as a database, which can then be processed in the template as required.

Upvotes: 5

Related Questions