Checking Content Zone if it has modules set

Posted by Giovanni Mattucci on January 24, 2017


I'm this helper method to check if a content zone has modules in it or not:

public class CheckContentZone
// get ContentSection Result
/// Pass string Content Zone name and return its contents as type of ContentSection
public static ContentSection contentZone(string contentZone = "")
ContentSection contentZoneContents = AgilityContext.Page.ContentSections.Where(i => i.Name == contentZone).FirstOrDefault();

return contentZoneContents;

// check value of ContentSection if empty.
/// Pass string Content Zone name and return if empty or not
public static bool hasContent(string contentResult)
var result = contentZone(contentResult);
return (result != null && result.ModuleContent != null);

Is this being done in the most efficient way? Is there a better solution to checking a content zone for modules?

   0 people like this question
15 30 50   per page
Hi Giovanni,

That's a clever way of detecting whether content zones have modules in them. The only way to do this is as you pointed out, checking the Page.ContentSections.

I've personally never had a case where i've needed to check this. Usually we'll just adjust with CSS if there are no children elements of a content zone containter. However, your method works and I don't see anything wrong with it.

Posted By: James Vidler

Previous Next


Log in with your Agility username and password or
register for the site

Log In