NVelocity advance lopping syntax

拥有回忆 提交于 2019-12-11 03:37:00

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/19236300/nvelocity-advance-lopping-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!