Vince Scordino Team : Web Development Tags : Web Development

Umbraco’s isLast() / isNotLast() Methods

Vince Scordino Team : Web Development Tags : Web Development

In the past, it’s always been a case of iterating through a loop and setting a counter variable to determine the index or position an item or node is currently at. Since playing around with Umbraco this week, I’ve found some pretty useful methods along with some handy overloads to be able to set a CSS class for “first” or “last” or even generating some HTML . EG: Pipes “|” between links.

Since generating HTML is the primary job of Razor, we want it to be as concise and as quick as possible. Say we have footer navigation as follows:

Privacy Policy | Terms & Conditions | Sitemap

We only want to insert a pipe delimiter if the current item isn’t last. 

@item.IsNotLast("|")

And that’s it! The pipe will only be inserted if the item is not the last in the set.

There’s a few others that will most definitely be of use to us devs:

IsFirst()

IsNotFirst()

IsEven()

IsOdd()