Umbraco 7 API Basics Introduction

In today's guide, I'm going to cover some of the basic Umbraco APi calls that you will need when you start working with Umbraco. This post is meant to be a quick reference guide to frequently used Umbraco queries. If you have any to add please leave a comment.

How To Get The Current Page Id

There are several ways to get the current page ID, directly from the context:


In Razor


After you get the current page Id, you will probably want to get a copy of the current document. To remind you, the document type is used when you want to get the data stored against a document type inside the database. A node on the other hand will return the data which has been published and cached. So, to get the current document we use:

     var pageId = ConvertToInt32(HttpContext.Current.Request["pageid"]);
     var doc = new Document(pageId)

To get the current Node, we use:

    var helper = new UmbracoHelper(UmbracoContext.Current);
    IPublishedContent content = umbracoHelper.TypedContent(Node.getCurrentNodeId());

Now if you are using a Surface Controller, you can make life a little easier, by using:

   IPublishedContent currentNode = Umbraco.TypedContent(CurrentPage.Id)

How To Get The Current Pages Document Type in Umbraco


How To Get All Siblings from the Current Page

If you want to get all of the current page siblings in Razor we can use:

@foreach (var item in Model.Content.Siblings())
    <a title="@item.Name" href="@item.Url">@item.Name</a>

How To Get All Children from the Current Page

@foreach (var item in Model.Content.Children())
    <a title="@item.Name" href="@item.Url">@item.Name</a>

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-35662136-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + ''; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();