Checking Content Zone if it has modules set

Posted by Giovanni Mattucci on January 24, 2017

Hello,

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

public class CheckContentZone
{
// get ContentSection Result
///<summary>
/// Pass string Content Zone name and return its contents as type of ContentSection
///</summary>
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.
///<summary>
/// Pass string Content Zone name and return if empty or not
///</summary>
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
   
  
 
 
   
Submit
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.

Regards,
James
Posted By: James Vidler

Previous Next

LOGIN

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




Log In

REGISTER












Register

FORGOT PASSWORD