Question

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?

Était-ce utile?

La solution

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top