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>