使用模板工具包从列表中过滤项目
如何过滤 Template Toolkit 中动态生成的列表中的某些项目? 我有一个 id 列表(也是动态生成的)和一个要排除的 id 列表,我需要只获取未排除的 id。最好的方法是什么? 示例代码:
[% SET ids = [1,2,4,10,11,12,13,17,19,20,21,50,51] %]
[% SET id_excluded = [10,11,13,20,50] %]
[% FOREACH pid IN ids %]
[% IF ?code to filter the ids? %]
[% pid %]
[% END %]
[% END %]
How can I filter some items that are in a dynamically generated list in Template Toolkit?
I have a list of ids (also dynamically generated) and a list of ids to be excluded and I need to get just the ids that are not excluded. What the best way to do that??
Sample code:
[% SET ids = [1,2,4,10,11,12,13,17,19,20,21,50,51] %]
[% SET id_excluded = [10,11,13,20,50] %]
[% FOREACH pid IN ids %]
[% IF ?code to filter the ids? %]
[% pid %]
[% END %]
[% END %]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
grep
VMethod 来处理列表,例如:它将产生以下结果:
Try the
grep
VMethod for lists, eg:Which produces the following: