When an item is set to unpublishable, all methods to get the item for a rendering with GlassMapper return null
.
public class PageHeaderController : GlassController
{
public override ActionResult Header()
{
BaseItem model = SitecoreContext.GetCurrentItem<BasePage>(); // null
model = GetLayoutItem<BasePage>(); // null
model = SitecoreContext.GetItem<BasePage>(RenderingContext.Current.Rendering.DataSource); // null
return View(model);
}
}
How can we get the item in that case to be able to provide a publishing preview for editors for items that are set to be published in the future?
The problem occurs whether we use the "Never Publish" setting or set the version to unpublishable or even when the version is set to be published in the future.
SitecoreContext
? From what I know there is no static methodSitecoreContext.GetCurrentItem
?SitecoreContext
is a member ofGlass.Mapper.Sc.Web.Mvc.GlassController
.