Post

How to get pagetype’s AvailablePageTypes programatically?

Find page type’s available types

1
2
3
IAvailablePageTypes availablePageTypes = ServiceLocator.Current.GetInstance<IAvailablePageTypes>();
AvailableSetting setting = availablePageTypes.GetSetting(this.Name);
IList<string> allowedPageTypeNames = setting.AllowedPageTypeNames;

If you need more information about your available Page Types you can do:

1
2
PageTypeRepository repository = ServiceLocator.Current.GetInstance<PageTypeRepository>();
IEnumerable<PageType> availablePageTypes = allowedPageTypeNames.Select(name => repository.Load(name));

You have to use include property not includeon property on your page type, otherwise you will not be able to get any result from GetSetting method.

Resources

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=72917&epslanguage=en http://cjsharp.com/blog/2013/04/11/a-closer-look-at-the-availablepagetypes-attribute-in-episerver-7/

Happy Coding! 😇

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.

© Vincent. Some rights reserved.