如何在模板工具箱中检测数组类型? [英] How to detect array type in Template toolkit?

查看:71
本文介绍了如何在模板工具箱中检测数组类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在模板"工具箱中为数组类型的附件检测一些变量. 有最佳做法吗?

I need to detect some variable for accessory to array type in Template toolkit. Are there best practices?

推荐答案

在将数据传递到模板之前,应先对其进行验证.您的数据的格式应该没有什么神秘之处.

Your data should be validated by the controller BEFORE it's passed to the template. There should be no mystery what format your data is in.

也就是说,最有用的检查方法就是测试 array 的大小:

That said, the most useful method to check this would just be testing the array's size:

[% IF var.size %]


[% END %]

这篇关于如何在模板工具箱中检测数组类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆