Create or Update text

Topics: Writing modules
Jul 18, 2012 at 4:17 PM
Edited Jul 18, 2012 at 4:25 PM

Unfortunately I had a serious issue yesterday and lost a TON of code while trying to push to my repository, including something really simple I had working in the editor shape for one of my parts.

I had some if/else logic that determined if I was creating a new item or updating an existing item and displayed text based on which one it was.

I cannot recall how it was written and have now spent a good hour trying different things in an attempt to duplicate the code.

Does anyone know how I can tell if the Model is a published item or not in the editor shape?

I could really use a memory jog (and more coffee). Thanks.



I think I may have gotten it. Is it simply?


Jul 24, 2012 at 5:45 PM

Almost: use the .IsPublished() extension method of IContent (import the Orchard.ContentManagement namespace, if not already done so).

Jul 24, 2012 at 5:49 PM
Edited Jul 28, 2012 at 6:25 PM

Correction: looking at the implementation of .HasPublished, that would work as well. I think it will see if there's at least a published version. Not sure what the difference would be in practice though as I have not used it before.

Jul 24, 2012 at 5:56 PM

Thanks...I'll play around with both to see if there's any noticeable difference.  .HasPublished()  appears to be working good for now.