Hi,
I'm looking for a coding tip.
Quite a few of the errors we're getting with Umbraco (be it via the Rich Text Editor with macros or the preview page) seem to have the underlying issue that we are referring to unpublished content.
This is often via a macro referring to the content in a content picker.
Is there a good way to test in code for whether content has been published, where I have the content id?
Good way to test for Unpublished Content
Hi, I'm looking for a coding tip. Quite a few of the errors we're getting with Umbraco (be it via the Rich Text Editor with macros or the preview page) seem to have the underlying issue that we are referring to unpublished content.
This is often via a macro referring to the content in a content picker.
Is there a good way to test in code for whether content has been published, where I have the content id?
Many thanks
If you can get content back as IPublishedContent then, by default, it should be published. So this would work (where 1234 is your content ID).
You can also reference
UmbracoContext.Current.InPreviewMode
to determine whether your page is being previewed or not (a source of some errors).Finally, if you can also use the ContentService if you are dealing with IContent. The following will check whether a node is published:
You shouldn't use ContentService in the front-end, though, as it has performance implications because it goes direct to the database.
is working on a reply...