There are couple of ways to get Umbraco content. Some returns the data from db and some does from the cache. Here is some details about them and how you use it in an umbraco project.
- IContent is managed by IContentService and is targetted at back-end, read-write access to content. It's what you want to use when you need to manage content.
- IPublishedContent is managed by the "content cache" and is targetted at front-end, read-only access to content. It's what you want to use when rendering content.
- Document and INode are (roughly) the legacy equivalents of IContent and IPublishedContent. They should not be used anymore, and will eventually be obsoleted entirely. So better ignore them.
Way 1
var contentService = new ContentService();
IContent content = contentService.GetById(123);
- Gets the content from the database.
- Returns both published and unpublished content.
- Preferred way to get editable content for CRUD operations in Umbraco 7+.
Way 2
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(123);
- Gets the content from the cache.
- Only returns published content.
- Preferred way to get cached content in Umbraco 7+.
Way 3
var content = new Document(123);
- Gets the content from the database.
- Returns both published and umpublished content.
- Old way to get editable content for CRUD operations.
Way 4
var node = new Node(123);
- Old way to get content from the cache.
- Only returns published content.
Comments
Post a Comment