I am using the Mustache templating library and trying to generate a comma separated list without a trailing comma, e.g.
red, green, blue
The question of whether Mustache offers an elegant way to do this has been answered, but it occurred to me that the most elegant way to do this may be to use CSS rather than changing the model.
Template:
{{#items}}- {{name}}
{{/items}}
CSS:
.csl li
{
display: inline;
}
.csl li:before
{
content: ", "
}
.csl li:first-child:before
{
content: ""
}
This works in IE8+ and other modern browsers.