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 :
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.
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...
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.
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 :
Any insight ?
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.
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
is working on a reply...