This is my third post in a series about creating .NET extension methods on a Sitecore item. I love extension methods and have been using them to wrap common operations on Sitecore items since they were introduced in .NET 3. The series of posts will also contain an architectural description on how to implement and maintain your extension methods so these are re-usable in all of your Sitecore solutions.
This is yet another quick extension method which has proven to be really useful. I will re-use it in later posts so better write about it first.
HasRenderings
The extension method checks if an item has renderings for the device item which is passed as parameter.
1 2 3 4 |
public static bool HasRenderings(this Item item, DeviceItem device) { return item.Visualization.GetRenderings(device, false).Any(); } |
As an overload I made a version which passes the Context.Device to the method as deviceItem parameter.
1 2 3 4 |
public static bool HasRenderings(this Item item) { return item.HasRenderings(Context.Device); } |
That was it.
I dare you to like this post..
Anders Laub Christoffersen
Anders has been working with Sitecore for over a decade and has in this time been the lead developer and architect on several large scale enterprise solutions all around the world. Anders was appointed the title of Sitecore Technical MVP in 2014 and has been re-appointed the title every year since then.
- Web |
- More Posts