Sin*_*nür 2 perl template-toolkit
假设我的模板中有以下内容:
[%- pages = [ 'one', 'two', 'three' ] -%]
<p>Go to page [%- ... -%]</p>
Run Code Online (Sandbox Code Playgroud)
假设EVAL_PERL是不成立(即我不能使用[%- PERL -%]块),我需要什么把里面[%- ... -%]的上方,从而得到下面的输出?
<p>Go to page "a randomly picked element of pages"</p>
Run Code Online (Sandbox Code Playgroud)
rand默认情况下,在Template中没有任何支持,因此您必须通过其他代码(如Slash)导入它或使用Template :: Plugin :: Math,例如:
[%- USE Math -%]
[%- pages = [ 'one', 'two', 'three' ] -%]
<p>Go to page [%- pages.${ Math.rand(pages.size) } -%]</p>
Run Code Online (Sandbox Code Playgroud)
输出:
$ tpage test.html
<p>Go to page three</p>
Run Code Online (Sandbox Code Playgroud)