Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 30, 2013 @ 20:48
    Nicholas Westby
    0

    Understanding ContentService: Published vs Saved Nodes

    I have just found out that I have been displaying saved/unpublished content on my site due to my apparent misuse of the ContentService. One reason seems to be that GetById will get the latest content (published or just saved). The solution in that case is to use GetPublishedVersion instead of GetById.

    However, from there, it is unclear to me when I am working with a published/saved content node. For example, if I call GetChildren based on an ID, will that get only the published content? If not, is the best practice to then call GetPublishedVersion on each of the resulting ID's? What about the other methods (e.g., will HasChildren return true if all of the children are saved but unpublished)?

    Note that this page doesn't really answer my questions: http://our.umbraco.org/documentation/v480/Reference/Management-v6/Services/ContentService

    I scanned this page and didn't find anything useful either: http://umbraco.com/follow-us/blog-archive/2013/1/22/introducing-contentservice-aka-the-v6-api.aspx

    I'm using Umbraco 6.1.3 with SQL Server CE.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Jan 28, 2014 @ 00:03
    Nicholas Westby
    101

    To anybody who comes across this, the simple answer is that IContent is something that came from the database and IPublishedContent is something that came from the XML cache.

    If you only want published stuff, only deal with the functions that accept IPublishedContent and return IPublishedContent.

    For example, if you want to get the published current page, you'd use the UmbracoHelper function TypedContent (rather than ContentService's GetById).

    Some functions that exist on the ContentService do not exist on UmbracoHelper, so you have to create your own (I think one I did this for was called something like GetContentByContentType).

Please Sign in or register to post replies

Write your reply to:

Draft