Thursday 6 July 2017

To check Sitecore item has presentation or not?

To do this from code behind,
First we should aware of that SitecoreItem should be of Page Template type Item, because Presentation generally applied on Page Item.
And Second thing is Page Template Item should have Standard Value So that in future If you are going to create a Page related to that Item then Page will have some default presentation applied from Standard Value.


So For Now we are checking only Page have Presentation or not:

private bool HasPresentationDetails(Item item)
{
return item.Fields[Sitecore.FieldIDs.LayoutField] != null
  && !String.IsNullOrEmpty(item.Fields[Sitecore.FieldIDs.LayoutField].Value);
}


It will check the layout field's value of that page Item.
If page item's layout field is not empty then presentation is applied to that Item else not.

No comments:

Post a Comment