jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

Start and End Tags (For use with Each Tag) #70

Closed sheigl closed 7 years ago

sheigl commented 7 years ago

I updated the each tag to set the context of the bool values start and end. When the collection starts the loop, start will be true, then false as it continues. End will be false until the collection length has been reached.

I know that you can tell if the collection has started iterating based on if the index is 0, however I could not find a way to tell if each tag had finished iterating.

I believe this is useful for html templating if you'd like to format html different based on start, middle, and end of a collection.

For example in a menu:

<li class="first">Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
<li class="last">Menu Item 4</li>