Frontend development

Explicitly typed content

When the model is known in advance, you may prefer to work with explicitly typed content.

The following example demonstrates this case for news items, but you can also use it for any kind of dynamic content.

Dynamic content is referenced with the full type name
Telerik.Sitefinity.DynamicTypes.Model.{ModuleName}.{TypeName}, for example
Telerik.Sitefinity.DynamicTypes.Model.Pressreleases.Child

In the following example, the NewsDto represents the News content:

C#
/// Class mapped to the news item class in Sitefinity.
[MappedSitefinityTypeAttribute(RestClientContentTypes.News)]
public class NewsDto : SdkItem
{
   /// Gets or sets the title.
   public string Title { get; set; }

   /// Gets or sets the publication date.
   public DateTime PublicationDate { get; set; }

   /// Gets or sets the date of creation.
   public DateTime DateCreated { get; set; }

   /// Gets or sets the url name.
   public string UrlName { get; set; }

   /// Gets or sets the item default url.
   public string ItemDefaultUrl { get; set; }

   /// Gets or sets the summary.
   public string Summary { get; set; }

   /// Gets or sets the content.
   public string Content { get; set; }

   /// Gets or sets the tags.
   public string[] Tags { get; set; }
}

There are the following things to note in the above example:

  • The NewsDto inherits from SdkItem
    This gives you the method GetValue, and the properties Id and Provider.
  • The class is marked with the attribute MappedSitefinityTypeAttribute.
    This holds the CRL type of the mapped Sitefinity type. In this case,
    RestClientContentTypes.News = "Telerik.Sitefinity.News.Model.NewsItem"
  • All of the custom properties are defined.

RECOMMENDATION: The REST SDK provides DTOs for all static types, such as news, events, lists, taxons, taxonomies, media, pages, and page templates. Therefore,  you do not need to define them yourself, unless you want to define your custom fields in a custom DTO class. In this case, we recommend inheriting from the already defined types and adding your custom fields there.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?