In my last guide, I explained how to create a template in Umbraco.  For a quick re-cap, a template in Umbraco language is similar to a view in MVC, its the basic building block to display HTML and CSS on your Umbraco websites.  I mean, having a blank website would be very dull and would attract zero visitors.  So, the next piece of the Umbraco puzzle is how to display data from your Umbraco Document types in your templates to make them a bit more exciting.

The Umbraco Helper

In MVC we have Razor and HTML helpers to display information for us, so an example of an MVC HTML Helper would be:

The above snippet will render the correct HTML for an anchor tag.  In the same vein, Umbraco provides us with an API for getting, displaying and formatting data from the CMS itself. To access the Umbraco helper is fairly straight forward.  In your Razor view, you need to make sure you are inheriting from 'UmbracoTemplatePage'

To use the helper you just type, @Umbraco. After typing the dot, IntelliSense should pop-up showing you all the available options to you. Some examples of the type of things you can do with the helper, include Get Typed Content

Truncate String

Getting data about the current page

Now we've covered the Umbraco helper, we still have two more tools in our arsenal, the @Model and the @CurrentPage.  Each will give you access to the current pages properties.  There seems to be a lot of confusion between the two. So let's first start with the syntax:

The first difference you might notice is between the two is that @Current page is a dynamic object.  This means you have to type in the 'Copyright' bit yourself, IntelliSense will not work.. because well it's dynamic. @model on the other hand, so it is strongly typed. This means that IntelliSense works and you can also write Linq against it. 

These two things are pretty useful, so, in general, @Model is the preferred choice, even though the @CurrentPage has slightly shorter syntax. The Umbraco helper, this exposes a lot of functionality to get data from Umbraco, manipulate data etc... We also have @Current page, a dynamic object-based approach to get data about the current page and @model a strongly typed helper.