Develop with Razor views
Developing Razor views within Contensis is really easy, all you need to do is create a new Razor view, add it to a template or page and you are ready to start coding.
The Razor view model
As part of a Contensis Razor view there are a number of properties available to you directly within the view context:
- CurrentNode - This is the ContentNode instance that represents the data for the current page.
- CurrentContext - This AppContext singleton instance represents the context of the current page and the website state.It includes convenient access to properties that you will want to use all the time such as the page object, project settings, the taxonomy tree, localisation values and security objects.
- CurrentUser - A convenient shortcut to the User instance, which can also be accessed through the Security property on the CurrentContext.
The CurrentNode property is where you go to get the data for the current page. The example below shows how to simply output the title of the current page in a Heading tag.
Once you have the current node you can then navigate to other nodes such as siblings or children to access their properties. The example below demonstrates how to list the content of a sub folder of the current node.
var parent = CurrentNode.Parent;
var subFolder = parent.Children<FolderNode>().Where(f => f.Title ==
The CurrentContext property is used when you need data other than that of the CurrentNode.
The example below demonstrates how to get the localised value of a label which has an id of 12345 using the Get() method on the Localisation property.
The example below demonstrates how to get a taxonomy node by path and then list the child keys out into a combobox.
var node = CurrentContext.Taxonomy.GetByPath(
The example below shows how find a group by name and then access all it's members
var users = CurrentContext.Security.Groups.FindBy(
The example below shows how to dynamically display markup dependant on whether the current user is logged in.
<h2>Welcome back @CurrentUser.DisplayName</h2>