Hi Pete,
You can use the below code:
var contentTypeRepository = ServiceLocator.Current.GetInstance();
var stringBuilder = new StringBuilder();
var contentTypes = contentTypeRepository.List(); // Retrieve all content types
foreach (var item in contentTypes)
{
if (item.ModelType != null)
{
var contentAreaProperties = item.ModelType.GetProperties().Where(p => p.PropertyType == typeof (ContentArea)); // Get all content area property types
foreach (var contentArea in contentAreaProperties)
{
var attribute = contentArea.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof (AllowedTypesAttribute)); // Get attributes from property
if (attribute != null)
{
foreach (var value in attribute.ConstructorArguments)
{
var allowedTypes =
(from blockType in (ReadOnlyCollection) value.Value
select ((Type) blockType.Value).Name).ToList();
stringBuilder.AppendFormat("Page type: {0}, ContentArea property: {1}, Allowed types: {2}", item.Name, contentArea.Name, string.Join(", ", allowedTypes));
}
}
}
}
}
Thanks a million, works perfectly.
May I ask how you figured this out? Is there some documentation on the episerver architecture that I haven't found? Lots of trial and error? Sheer brilliance? Or should it have been obvious?
Yes there's plenty of documentation about the architecture: http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/75/. You could also download the Alloy Tech demo site for a lot of best practices. And the rest is just experience;)
@Patrick: in an ironic twist, clicking your link leads to a 404 :-)
Here's the correct clickable link: http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/75/
Hi,
How can I get the names of the "AllowedTypes" for a contentarea of a page?
I'm trying to create some documentation for our webeditors, I'd like to create a list of the allowable types for each contentarea of each page type. (Preferably translated using the language files)
Thanks.