Copied to clipboard

Flag this post as spam?

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


  • Mus'ab 155 posts 380 karma points notactivated
    Sep 30, 2019 @ 17:41
    Mus'ab
    0

    How to get and render unpublished nodes using IContentFinder ?

    I have unpublished nodes in the back office they were unpublished in order to reduce the cash file and to increase the navigation speed, but i couldn't render the unpublished nodes.

    I used the following example to handle the nodes that are beneath the "2017" which is unpulbished.

    public class MyContentFinder : IContentFinder
    {
       public bool TryFindContent(PublishedRequest contentRequest)
       {
    
        // handle all requests beginning /woot...
        var path = contentRequest.Uri.GetAbsolutePathDecoded();
        if (!path.StartsWith("/2017"))
            return false; // not found
    
        var content = contentRequest.UmbracoContext.Content.GetByRoute(path);
    
    
        if (content == null) return false; // not found let another IContentFinder in the collection try to find a document
    
        // render that node
        contentRequest.PublishedContent = content;
        return true;
    
    
        throw new NotImplementedException();
    }
    }
    

    What I noticed, I could not get unpulbished content by GetByRoute() with a given path.

    so the below line could not do the what I wanted :

     contentRequest.PublishedContent = content;
    

    Any insight ?

  • Bo Jacobsen 438 posts 1818 karma points
    Sep 30, 2019 @ 20:18
    Bo Jacobsen
    0

    Hi Mus'ab.

    If you wanna find unpublished content then you need to to use the IContentService https://our.umbraco.com/documentation/reference/management/services/contentservice/, but it will also return IContent. So you need to convert it to IPublishedContent somehow, wich i dont recommend.

    The downside of this is that IContentService make one or more database calls, so you rather wanna use the cashe. If you feels like your cashe is slow it might be because of some customcode.

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Sep 30, 2019 @ 20:39
    Marc Goodson
    0

    This is for V7, but we wrote an article about how to retrieve 'archived' content in an Umbraco site:

    https://www.moriyama.co.uk/about-us/news/blog-the-need-for-archived-content-in-umbraco-and-how-to-do-it/

    that might provide some inspiration...

    But as Bo says, you won't find it in the Umbraco Cache when it's unpublished...

    but you can create your own content object that implements IPublishedContent from Examine or another location (we used a custom database table) or even using the ContentService...

    and your IContentFinder can return your custom IPublishedContent object...

    regards

    Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies