Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Parse an EPiServer ContentArea and get contents.
private object ParseContentArea(ContentArea contentArea, LanguageSelector language)
{
if (contentArea == null || contentArea.Items == null)
{
return null;
}
var contentLinks = contentArea.Items.Select(x => x.ContentLink).ToList();
var content = _contentRepository.GetItems(contentLinks, language);
var children = new List<object>();
foreach (var item in content)
{
var properties = new Dictionary<string, string> {
{ "pageid", item.ContentLink.ID.ToString(CultureInfo.InvariantCulture) }
};
foreach (var prop in item.Property.Where(x => x.IsPropertyData))
{
string propValue;
switch (prop.Type)
{
case PropertyDataType.PageReference:
propValue = ((PageReference)prop.Value).GetExternalUrl();
break;
case PropertyDataType.ContentReference:
propValue = ((ContentReference)prop.Value).GetExternalUrl(language.LanguageBranch);
break;
default:
propValue = Convert.ToString(prop.Value);
break;
}
properties.Add(prop.Name, propValue);
}
children.Add(properties);
}
return children;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment