We need to work with some unpublished content, but we want to get this data as an IPublishedContent because the API is much easier to use. For example for an IPublishedContent we can use Property Value Converters.
The unpublished content doesn't need to be edited so there is no need to use
IContent, but for now that is the only way to get unpublished content.
Is there a way to get convert an IContent to IPublishedContent? I know Nested Content and Archetype can also return their data as an IPublishedContent.
I've looked at the examples and I've created an experimental extension method that can convert an IContent to an IPublishedContent. I'm not really sure if I've implemented everything correct, but I did some some tests and everything seems to work.
Most of the code is copied from the PublishedContent example. It had a lot of internal methods which I had to copy to get it work.
// Get the unpublished version of the current node.
var content = this.Services.ContentService.GetById(nodeid);
// Convert it to an IPublishedContent. So this IPublishedContent has the unpublished version.
var publishedContent = content.ToPublishedContent();
I've tried things like publishedContent.DescendantsOrSelf() and that seems to be working.
Convert IContent to IPublishedContent
Hello,
We need to work with some unpublished content, but we want to get this data as an IPublishedContent because the API is much easier to use. For example for an IPublishedContent we can use Property Value Converters.
The unpublished content doesn't need to be edited so there is no need to use IContent, but for now that is the only way to get unpublished content.
Is there a way to get convert an IContent to IPublishedContent? I know Nested Content and Archetype can also return their data as an IPublishedContent.
Jeroen
Nothing built-in that I can remember of, in v7. So you'd have to implement your own IPublishedContent implementation. Works.
(hint: Umbraco.Web.PublishedCache.PublishedNoCache.PublishedContent in 7cc)
Thanks for the tip. I think this is also a nice example: https://github.com/imulus/Archetype/blob/8e009143708073bc6384487e4707952238414f6b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedContent.cs
Found the Umbraco.Web.PublishedCache.PublishedNoCache.PublishedContent. That also looks like a nice example :-) https://github.com/umbraco/Umbraco-CMS/blob/dev-v7-contentcache/src/Umbraco.Web/PublishedCache/PublishedNoCache/PublishedContent.cs
I've looked at the examples and I've created an experimental extension method that can convert an IContent to an IPublishedContent. I'm not really sure if I've implemented everything correct, but I did some some tests and everything seems to work.
Most of the code is copied from the PublishedContent example. It had a lot of internal methods which I had to copy to get it work.
The extension method can be found here: https://gist.github.com/jbreuer/dde3605035179c34b7287850c45cb8c9
Now it's possible to do this:
I've tried things like
publishedContent.DescendantsOrSelf()
and that seems to be working.Jeroen
I blogged about how you can convert IContent to IPublishedContent. It also has a working example: http://24days.in/umbraco-cms/2016/umbraco-edge-case-stories/#convert
Jeroen
Do anyone have an extensions that works with Umbraco 8
Hi Jeroen,
Just to get clarification that, the package Enum Lists will work with v8 ? or is their any plans to upgrade to Latest.
https://our.umbraco.com/packages/backoffice-extensions/enum-lists
Thanks,
Gurumurthy J V
is working on a reply...