How can I output <hr> after every iteration except last one with mustache.js. I tried javascript for loop but I couldn’t get rid of last <hr>. (Some people suggest using handlebars.js but I would like stay with mustache.)
Here is my json (the list gets bigger as more employees get added)
{
employees: [
{firstName: "John", lastName: "Smith"},
{firstName: "John", lastName: "Doe"},
{firstName: "Jane", lastName: "Doe"}
]
}
I want this html output:
John Smith
<hr>
John Doe
<hr>
Jane Doe
Looking at the Mustache Manual, you’ll want to use what’s referred to as “Inverted Sections”. From the manual:
To utilize this, you could add an extra attribute to the last employee to distinguish it.
JSON:
Mustache Template:
This is very similar to what the Mustache Demo showcases, using the “first” attribute on the first object in the array of colors.