1

In my velocity template, I want to concat strings delimited by comma(,) using foreach loop.

#foreach($field in $MyObject.Fields)
    ${field.Name},
#end

This results in an extra comma at the end. How can avoid the last unwanted comma?

PS: I am using NVelocity 0.4.2

Thanks

Krishna Sarma
  • 1,852
  • 2
  • 29
  • 52
  • 1
    see http://stackoverflow.com/questions/8196828/velocity-do-something-except-in-last-loop-iteration – lrkwz Oct 28 '14 at 10:21

1 Answers1

1

I can't recall where NVelocity 0.4.2 comes from (i.e. Castle Project or the original port), but if it has the foreach looping directives, you can use them. Take a look at this recently asked question on the same topic:

NVelocity advance lopping syntax

If it doesn't have support for that, you can use the special $velocityCount variable with an #if directive to determine if you want a comma or not.

Community
  • 1
  • 1
Jonathon Rossi
  • 4,149
  • 1
  • 22
  • 32