Template: Toolkit Variable Processing

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

So, in a script, I write smth like:

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

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

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

And I expect the pid variable to be set to "1", and the plink.par file is inserted. But instead, I get on my html page the exact contents of the descr variable:

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

ie, this variable remains raw on TT.

How to make a TT process its contents?

+4
source share
1 answer

You can use the eval filter :

 <p>[% descr | eval %] 

From the related manpage:

The eval filter evaluates the block as template text, processing any directives built into it. This allows template variables to contain template fragments or for some method that must be provided to return template fragments from an external source, such as databases, which can then be processed in the template as needed.

+4
source

Source: https://habr.com/ru/post/1413853/


All Articles