NVelocity提前修剪语法 [英] NVelocity advance lopping syntax

查看:118
本文介绍了NVelocity提前修剪语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在做一个涉及Nvelocity模板的项目,但是,我需要使用advance foreach,我可以找到参考,但我无法弄清楚它是如何工作的,请参阅链接

  #foreach($ mark in $ markPoint)hardcodetext($ l)#end 

但是,我需要添加,项目之间,硬编码会留下一个最后一个项目,我不希望,
任何帮助吗?

解决方案

NVelocity特殊的foreach循环指令只是foreach指令中的嵌套部分,您可以定义模板的位。以下是在每个项目之间插入逗号的基本结构示例:

  #foreach($ i in [1 .. 5])
#between

#each
$ i
#end

由于嵌套指令不能在同一行中包含任何其他内容,并且由于末尾包含的换行符,如果您关心额外的空白出现,它们可能会有点痛苦,所以如果你希望输出看起来完全像1,2,3,4,5而没有任何空格,你需要删除一些如下所示的新行:

  #foreach($ i in [1..5])#
,#each
$ {i} #end


Currently I am doing a project which involve Nvelocity template, however, I need use advance foreach, I could find the reference, just I could not figure out how does it works,reference link

#foreach($l in $markPoint)hardcodetext($l)#end

however, I need add "," between items,hardcode will left one after last item, which I don't want, any helps?

解决方案

The NVelocity special foreach looping directives are just nested sections inside the foreach directive, which you define bits of the template. Following is an example of the basic structure for putting a comma between each item:

#foreach($i in [1..5])
#between
,
#each
$i
#end

Because the nested directives cannot contain anything else on the same line they and because of the newline that is included at the end they can be a bit of a pain if you care about extra whitespace appearing, so if you want the output to look exactly like "1,2,3,4,5" without any whitespace you'll need to remove some of the newlines between things like follows:

#foreach($i in [1..5])#between
,#each
${i}#end

这篇关于NVelocity提前修剪语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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