Computer Magic Logo
Get the root nodes

Monday, February 15, 2016

Published by Aristotelis Pitaridis

We can use the TypedContentAtRoot() member function in order to get a list of all the root content nodes.

var rootNodes = Umbraco.TypedContentAtRoot();

The previous line of code works in a View but if we want to get the tree nodes in a class then we have to use the following code snippet.

var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
var rootNodes = umbracoHelper.TypedContentAtRoot();