Copied to clipboard

Flag this post as spam?

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


  • Johan Dahlström 33 posts 146 karma points
    Mar 09, 2020 @ 22:21
    Johan Dahlström
    0

    Get unpublished page as IPublishedContent

    I have a page that has never been published. How can I fetch this particular page as IPublishedContent using your services?

    I know that I can fetch it as IContent, but as far as I can tell, there is no way to convert it to IPublishedContent in Umbraco 8.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Mar 09, 2020 @ 23:00
    Paul Wright (suedeapple)
    0

    You just need to save the node, using the ICONTENT.

    It will then make that node available via IPublishedContent, as it will appear in the cache.

  • Johan Dahlström 33 posts 146 karma points
    Mar 09, 2020 @ 23:09
    Johan Dahlström
    0

    Thanks for the response. You mean save and publish, right? In this case, I don't want to show the page to the users yet.

    I guess I have to perform a SaveAndPublish > Unpublish? Or is there a better way?

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Mar 09, 2020 @ 23:24
    Paul Wright (suedeapple)
    0

    Depending on what particular version of Umbraco you are using, there's several overrides on the "save" event.

    https://our.umbraco.com/apidocs/v7/csharp/api/Umbraco.Core.Services.IContentService.html#UmbracoCoreServicesIContentServiceSaveSystemCollectionsGenericIEnumerableUmbracoCoreModelsIContent_SystemInt32SystemBoolean_

  • Johan Dahlström 33 posts 146 karma points
    Mar 09, 2020 @ 23:30
    Johan Dahlström
    0

    I'm using Umbraco 8.5.4. So what you are suggesting is basically what I mentioned in my previous post?

  • Malthe Petersen 68 posts 383 karma points c-trib
    Mar 10, 2020 @ 16:19
    Malthe Petersen
    100

    Hi Johan.

    You can get the preview content from the cache by using UmbracoContext.Content.GetById(true, Id).

    The “true” is you telling that you would like to get the saved, not yet published, version of the content.

    Hope this helps.

    Regards Malthe

  • Johan Dahlström 33 posts 146 karma points
    Mar 10, 2020 @ 19:12
    Johan Dahlström
    0

    Hi Malthe,

    Excellent, exactly what I was looking for, thanks!

  • Vlael Layug 13 posts 115 karma points c-trib
    Jul 30, 2020 @ 12:50
    Vlael Layug
    0

    Hello Malthe,

    Tried using it on Umbraco v7 - UmbracoContext.ContentCache.GetById(true, Id); but it's giving me an error.

    at umbraco.presentation.preview.PreviewContent.EnsureInitiaenter code herelized(User user, String previewSet, Boolean validate, Action initialize)
    
  • Malthe Petersen 68 posts 383 karma points c-trib
    Jul 30, 2020 @ 15:58
    Malthe Petersen
    0

    Hey

    I am not sure how it is done in v7, or even if it is possible, but the above works in v8.

Please Sign in or register to post replies

Write your reply to:

Draft