Add back Container Pages in EPiServer 7.5
Container pages in EPiServer 7.5 is no more a built-in system type which is actually good because now everything in based on template implementation.
If you are still looking for a solution for container pages code snippets below could be useful.
I kind of liked solution found in AlloyTech Mvc sample site for 7.0 – when you define interface and your page type is “implementing” that eventually your page instance SelectedTemplate is set to null – resulting in so called container pages.
1
2
3
4
5
6
7
[ContentType(GroupName = GroupNames.MyGroup,
DisplayName = “Sample page”,
GUID = “9B02B266-D3C9-409E-93D2-21D26657F410″,
AvailableInEditMode = true)]
public class SamplePage : BasePageData, IContainerPage
{
…
In EPiServer 7.5 solution is much more cleaner. All you need to do is register new UIDescriptorInitializer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[ServiceConfiguration(typeof(IUIDescriptorInitializer))]
public class ContainerPageUIDescriptorInitializer : IUIDescriptorInitializer
{
public void Initialize(UIDescriptorRegistry registry)
{
var containerTypes = TypeAttributeHelper.GetTypesChildOf<IContainerPage>();
foreach (var type in containerTypes)
{
registry.Add(new UIDescriptor(type)
{
DefaultView = CmsViewNames.AllPropertiesView,
IconClass = ContentTypeCssClassNames.Container
});
}
}
}
This initializer searches for all types those are implementing IContainerPage
interface and registers container page like UI descriptor for them. Interface could be of course defined by you.
1
TypeAttributeHelper.GetTypesChildOf<IContainerPage>();
This is just a small helper class taken from other my plugins that finds all types that is child of specified type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class TypeAttributeHelper
{
public static IEnumerable GetTypesChildOf()
{
var allTypes = new List();
foreach (var assembly in GetAssemblies())
{
allTypes.AddRange(GetTypesChildOfInAssembly(typeof(T), assembly));
}
return allTypes;
}
private static IEnumerable GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
private static IEnumerable GetTypesChildOfInAssembly(Type type, Assembly assembly)
{
try
{
return assembly.GetTypes().Where(t => t.IsSubclassOf(type) && !t.IsAbstract);
}
catch (Exception)
{
// there could be situations when type could not be loaded
// this may happen if we are visiting *all* loaded assemblies in application domain
return Enumerable.Empty();
}
}
}
Happy containering!
[eof]
Comments powered by Disqus.