Menu

#2 for loop enhancement

open
nobody
5
2008-07-10
2008-07-10
Anonymous
No

I have a collection derived from IEnumerable<T> and I'd like to iterate over that collection in my VTL file and render its data. If the collection is empty, I'd like to do something else (e.g. print "no data available").

How about the following syntax?

#foreach ($item in $collection)
$item<br/>
#else
<h1>No items available!</h1>
#end

The else clause would only be executed if no items were in the collection.

This is similar to Python's for loop (see: http://docs.python.org/ref/for.html\).

Discussion


Log in to post a comment.