加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – Template :: Toolkit不会将变量计算为字符串

发布时间:2020-12-15 21:47:11 所属栏目:大数据 来源:网络整理
导读:我正在使用 Template::Toolkit并在for循环中我试图更改对象的时区: [%- FOR item IN c.user.items -%] [% item.date.set_time_zone(c.user.timezone.name) %] Date: [% item.date %] br /[% END %] 它工作并且它改变了时区,但是set_time_zone函数返回DateTi
我正在使用 Template::Toolkit并在for循环中我试图更改对象的时区:
[%- FOR item IN c.user.items -%] 
    [% item.date.set_time_zone(c.user.timezone.name) %]

    Date: [% item.date %] <br />
[% END %]

它工作并且它改变了时区,但是set_time_zone函数返回DateTime对象,然后将其评估到页面上.所以每次围绕for循环时,字符串都会被评估并放到页面上.我知道其他一些模板系统有两组标签,一组表示运行此代码,另一组表示评估此标记并将其放在页面上. Template :: Toolkit有这样的东西吗?我看了,但似乎找不到任何东西.到目前为止,我发现没有在页面上评估字符串的唯一方法是设置返回给变量的值:

[% var = item.date.set_time_zone(c.user.timezone.name) %]

有没有人知道在Template :: Toolkit中更好的方法?

解决方法

试试CALL指令:
[% CALL item.date.set_time_zone(c.user.timezone.name) %]

从文档:

The CALL directive is similar to GET in evaluating the variable named,but doesn’t print the result returned. This can be useful when a variable is bound to a sub-routine or object method which you want to call but aren’t interested in the value returned.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读