Friday, May 6, 2016

Renderings

1. To get a count of renderings in a placeholder (gets sublayouts only):

public static int GetRenderingCount(string placeholderKey)
    {
      var renderingReferences = Sitecore.Context.Item.Visualization.GetRenderings(Context.Device, false);
      return renderingReferences.Count(r => r.Placeholder.TrimEnd('/').EndsWith(placeholderKey, StringComparison.OrdinalIgnoreCase));

    }


2. To get the layout used on the item:

Sitecore.Context.Item.Visualization.GetLayout(Sitecore.Context.Device)

No comments:

Post a Comment