Umbraco’s isLast() / isNotLast() MethodsAdd to My Brief

Vince Scordino | 31/10/2011

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() 

 

tags: Web Development

Interested in learning more?

Wiliam is a leading supplier of web solutions and can provide expert advice to assist your business or organisation online.

Make enquiry   Request quotation

Comments

Share this page

Print this page Email this page to a friend Bookmark and Share

No Brief added yet.

My Brief results-driven approach emphasises a commitment to our clients needs through strategic analysis and best-practice.

Add to My Brief

Click on this icon to save item into My Brief. Retrieve, email and print

Drag & Drop

Drag & drop any iten with this icon into My Brief. Retrieve, email and print

Search Blogs