Getting Data

Get data in Razor functions

You can get data from data types by using the Data.Get method:

    @foreach (var myEvent in Data.Get<Demo.Event>())
		<li>@myEvent.Date: @myEvent.Title</li>    

In the sample above, data from the Demo.Event data type is presented as a list of items.

To see this code in action, create a data type called "Demo.Event", add two fields - "Title" (String) and "Date" (Date) - and add some data to this data type, or download and install the package with it: Demo.C1RazorFunctions.Events

For demo purposes, you can also use pages (IPage) as your data type without creating other data types, like this:

    @foreach (var myPage in Data.Get<IPage>())
        <li>@myPage.ChangeDate: @myPage.Title</li>    

For more sample code, please also see "List to Details".

Page data folders and page meta types

You can also use Data.Get when accessing page-specific folder and meta data. Here, you should make use of SitemapNavigator to get the current page ID (CurrentPageId) and filter data by this specific page.

var myFolderData =
from d in Data.Get<My.Folder.Type>()
where d.PageId == SitemapNavigator.CurrentPageId
select d;
You can always fetch the "built-in" page fields through SitemapNavigator, too. For example, SitemapNavigator.CurrentPageNode.Description will give you the description of the current page node.

(In the example above, Sitemap is an initialized SitemapNavigator object.)