Computer Magic Logo

Saturday, August 8, 2015

Published by Aristotelis Pitaridis

The CurrentPage object is the dynamic representation of the current page model which allows us to dynamically access the fields of a page. The type of the CurrentPage object is Umbraco.Web.Models.DynamicPublishedContent.

We can use the CurrentPage object in order to access fixed properties which has been defined by Umbraco. The example below shows us how to access the fixed properties of the CurrentPage object.


The output of the code above will be the following.

7/27/2015 3:46:31 PM
8/2/2015 9:53:01 AM
Aristotelis Pitaridis
Aristotelis Pitaridis

When we create pages we have the fixed properties but we also have the custom properties that we define. In order to access a custom property we use the same syntax. For example if we have a custom property with alias name description we can use the following code in order to access the value of the property.


All the pages in Umbraco have an id. We can use the Content member function of the Umbraco object in order to get the DynamicPublishedContent object for a page that we know the id. Let’s see an example.

    var MyPage = Umbraco.Content(1110);


In this example we get the DynamicPublishedContent object for the page with id 1110 and we store it in the MyPage variable. After that we can use this variable to access all the properties the way we do it with the CurrentPage object.