Allow a child page to be created under specific parent

Vote:
 

Hello guys,

I have a need to create a content page (say BlogPage) and it needs to be available to create only under BlogContainer Type page. While I can use the AvailableContentType option on various pages where to include or exclude, I am thinking more from a long term that if new page types are added, I don't have to update the list on them. Any ideas in achieving this would be helpful.

#285345
Aug 11, 2022 3:37
Vote:
 

AvailableContentType also has IncludeOn and IncludeOff ExcludeOn.

maybe you can use this in combination with a base page thats common to all your pages?

I believe IncludeOn and IncludeOff are prioritized over Include / Exclude so most likely the right combinations of these will allow you to specify a default behaviour and then only add to a list when you need an exception to the rule.

#285350
Edited, Aug 11, 2022 9:45
Vote:
 

Not IncludeOff, but ExcludeOn.

I think DD is aware of those attributes, he/she is just wondering if there is a way to make it more future proof. I am not aware of such method, except for using the base class, but it is not completely future proof.

#285351
Aug 11, 2022 10:26
Surjit Bharath - Aug 11, 2022 10:31
doh! typo(s). Thanks.
Vote:
 

If you don't want to use a base class, you can create an interface with a UI Descriptor and use that in content restrictions.  I do something similar with blocks in builds:

public interface IContentBlock : IContentData
{
}

[UIDescriptorRegistration]
public class ContentBlockUIDescriptor : UIDescriptor<IContentBlock>
{
}

public class HomePage : SitePageData
{
    [Display(
        Name = "Content",
        GroupName = GroupNames.Content,
        Order = 10)]
    [AllowedTypes(typeof(IContentBlock))]
    public virtual ContentArea? Content { get; set; }
}

You could adapt this solution for pages by setting up the following:

public interface IBlogPage : IContentData
{
}

[UIDescriptorRegistration]
public class BlogPageUIDescriptor : UIDescriptor<IContentPage>
{
}

[ContentType(
    DisplayName = "Blog Container Page",
    GUID = "C64CDD71-5AB6-44E6-84B6-92266F4B8FA6",
    GroupName = GroupNames.Content)]
[AvailableContentTypes(Availability.Specific, Include = new []{typeof(IBlogPage )})]
public class BlogContainerPage : SitePageData
{
}

[ContentType(
    DisplayName = "Blog Page",
    GUID = "F052D9C2-1343-48C1-A0FC-13D4748032E0",
    GroupName = GroupNames.Content)]
public class BlogPage : SitePageData, IBlogPage
{
}
#285431
Aug 12, 2022 15:22
Vote:
 

Hello Marc,

Thanks for the inputs. The solution above is for a parent page to restrict what child pages it can have. I am looking for something, where a page (child page) in this context can restrict under which parent it can be created. Let me know if am missing something.

#285568
Aug 15, 2022 12:52
Vote:
 

Hello DD,

I did some experimentation to try and solve your problem. I noted that If a type implemented both an interface or inherited a base class that met the criteria of both IncludeOn and ExcludeOff on a child type, then the child could not be placed under the parent despite it matching the IncludeOn types and if the parent page type matched both criteria then it could not have any pages created under it.  And when you restrict to just using IncludeOn without an ExcludeOn then it really becomes a bit pointless.

Personally I would just stick to restricting from the top downwards (e.g. have the parents restrict what is allowed beneath them).  From my own experience, these kind of page restrictions are often one of the first things that gets removed once a project goes into BAU as it inhibits the Information Architecture of the site.

#285569
Edited, Aug 15, 2022 13:32
Vote:
 

Thank you for the explanation. I am also seeing issues with Exclude property as it does not behave as expected so I am going to stick to top down approach for now and just use the Include property on parent pages.

#285792
Aug 19, 2022 3:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.