English 中文(简体)
模板: Toolkit 变量处理
原标题:Template::Toolkit variable processing

我从perl 使用 TT, 并试图插入模板和处理一个变量, 该变量本身包含 TT 指令 。

所以,在剧本中,我写着Smth,就像:

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

TT模板(收到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 %]

即,该变量不由TT处理。

我如何让TT处理它的内容?

最佳回答

http://template-toolkit.org/docs/manual/Filters.html#section_eval_evaltt" rel=“noreferrer”>eval过滤器 :

<p>[% descr | eval %]

从链接的 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.

问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签