繁体   English   中英

Perl 模板工具包 - 如何将模板 output 结果返回到变量中?

[英]Perl Template Toolkit - how to return the template output result into a variable?

Perl Template Toolkit - how to return the template output result a into variable, so that it can be later processed or placed into a html layout using in a controller.

答案是,结果 output 的变量必须作为第三个参数通过引用传递

$template->process(
        'dir/template.tt',
        {
            'par1'      => $par1,
            'par2'     => $par2,
        },
        \$output
    )   

它在文档中间接提到,但从非常冗长和技术描述中可能并不明显(我认为不清楚,几乎听起来没有选项将其作为变量传递,除非它是实现打印变量的回调,事实并非如此)

该值可能是以下之一: 表示将打开的文件名(相对于 OUTPUT_PATH,如果已定义)和写入的 output 的纯字符串; 为 output 打开的文件 GLOB; 对附加输出/错误的标量(例如文本字符串)的引用; 对被调用的子程序的引用,将 output 作为参数传递; 或任何实现 print() 方法的 object 引用,该方法将被调用,将生成的 output 作为参数传递。

https://metacpan.org/pod/Template#process($template,-%5C%25vars,-$output,-%25options)

即使在谷歌中搜索它也不会轻易地提供特定的链接结果,并且在多次尝试使用查询'perl template toolkit output template contents in variable process'后才提供非常晚的结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM