Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Create a page Programmatically problem

Vote:
 

How can I get all the "AvailablePageTypes" from the pagetype? without identifying the correct value, it gives me an error.

 

Thanks

#72917
Jul 03, 2013 4:02
Vote:
 
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:

PageTypeRepository repository = ServiceLocator.Current.GetInstance<PageTypeRepository>();

IEnumerable<PageType> availablePageTypes = allowedPageTypeNames.Select(name => repository.Load(name));

    

#72919
Jul 03, 2013 9:18
Vote:
 

Hi Alf

Thanks for your help, I tried your code, somehow the availablePageTypes.GetSetting(pagetypename) always return empty, I expanded availablePageTypes, I could see all the values from _modelSettingRepository property, but the "GetSetting" seems always return a new instance of AvailableSetting

 

Thanks

#72997
Jul 03, 2013 16:43
Vote:
 

Ok. Strange cause when I do this on AlloyTemplates:

EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.PageTypeAvailability.IAvailablePageTypes>().GetSetting("StartPage").AllowedPageTypeNames

The result is:

Count = 7
    [0]: "ContainerPage"
    [1]: "ProductPage"
    [2]: "StandardPage"
    [3]: "NewsPage"
    [4]: "ArticlePage"
    [5]: "SearchPage"
    [6]: "LandingPage"   

Have you checked that the name of the Page Type you are 100% correct to the Page Type Name. You want the name of the Page Type, not the localized name.

If you have the Type of your Page Type, you can find its name by following:

ServiceLocator.Current.GetInstance<PageTypeRepository>().Load<MyPageType>().Name

 

Another thing you could try if you want to check whether a specific Page Type may be created under another specific Page Type is:

EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.PageTypeAvailability.IAvailablePageTypes>().IsAllowed("StartPage", "StandardPage")

    

#73001
Jul 03, 2013 17:04
Vote:
 

ah ha, cuz I used "IncludeOn" attribute not Include, that's why GetSetting return nothing. What's the difference between them? 

#73002
Jul 03, 2013 17:12
Vote:
 

Take startpage and standardpage for example.

if you write includeon(startpage) on the standardpage it will be added to the available page types on startpage.

If you write include(standardpage) on startpage you will add standardpage on the startpage pretty much the same way as previous example.

it provides different ways to define what page types should be allowed or disallowed as children on other page types.  

#73004
Jul 03, 2013 18:16
Vote:
 

Hi Alf

 

Thanks for your clear explaination.  However I don't think the GetSetting works for includeon property but include. I have a landingpage type and detailpage type, I set includeon(landingpage) property on detailpagetype, it's not working. After I change to include, the GetSetting returns the result this time.  

#73010
Jul 04, 2013 1:11
Vote:
 

Accually I think GetSettings include Page Types added by AvailableOn.

I have made these changes to AlloyTemplates

[SiteContentType(
    GUID = "17583DCD-3C11-49DD-A66D-0DEF0DD601FC",
    GroupName = Global.GroupNames.Products)]
[SiteImageUrl(Global.StaticGraphicsFolderPath + "page-type-thumbnail-product.png")]
[AvailablePageTypes( 
    Availability = Availability.Specific,
    IncludeOn = new[] { typeof(StartPage) })]
public class ProductPage : StandardPage


[ContentType(
    GUID="19671657-B684-4D95-A61F-8DD4FE60D559",
    GroupName = Global.GroupNames.Specialized)]
[SiteImageUrl]
[AvailablePageTypes(
    Availability.Specific,
    Include = new[] { typeof(ContainerPage), typeof(SearchPage), typeof(LandingPage) }, // Pages we can create under the start page...
    ExcludeOn = new[] { typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(SearchPage), typeof(LandingPage) })] // ...and underneath those we can't create additional start pages
public class StartPage : SitePageData

Now, the only reference between ProductPage and StartPage is the IncludeOn found on ProductPage. Again, IncludeOn means that the current Page Type (ProductPage) should be included as Allowed Page Type to Start Page. And Include means that ContainerPage SearchPage and LandingPage should be included to the current Page Type (StartPage).

Note that since ProductPage inherits StandardPage I have removed both typeof(ProductPage) and typeof(StandardPage) from the Include on StartPage.

ExcludeOn is not relevant in this example.

This is my result when I run the following code

EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.DataAbstraction.PageTypeAvailability.IAvailablePageTypes>().GetSetting("StartPage").AllowedPageTypeNames
Count = 4
    [0]: "ContainerPage"
    [1]: "SearchPage"
    [2]: "LandingPage"
    [3]: "ProductPage"

And when I remove IncludedOn the result from the same code does not include ProductPage:

    [0]: "ContainerPage"
    [1]: "SearchPage"
    [2]: "LandingPage"
#73066
Jul 04, 2013 23:34
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.