Try our conversational search powered by Generative AI!

Limit creation of PageTemplates under specific folder path

EJ
EJ
Vote:
 

Hi all,

I have a tricky question here. Does anybody know how you can only allow a pagetype to be created under a certain folder in the folder-hierarchy?

Root
---> Home
---> Stuff
---> Secrets
---> ---> MyPage

So in the structure above, I want a page only to be allowed under the fodler named "Secrets". Is this possible to achieve? :)

#230090
Oct 29, 2020 15:42
Vote:
 

Hi EJ,

You could hook to the IContentEvents.CreatingContent and check is the parent name "Secrets" and if not, then use the event argument to cancel the creation.

BUT maybe a better approach would be to have specific content type for your "Secrets" page/container page and then only allow certain content types below it using the AvailableContentTypes attribute, see documentation (the sample uses the attribute).

#230093
Oct 29, 2020 17:12
EJ
Vote:
 

Hi Antti, Thank you for quick answer with both the solution I asked for and a best practices suggestion :) 

I could create a container page under "Secrets" and allow only certaing content types below it, thats fine. But those content types could still be allowed under the other folders, right? Is it possible with an AllowedParentTypes sort of functionality?

#230095
Oct 29, 2020 17:51
Vote:
 

Hi EJ,

You could also use the "Secrets" folder as a specific container content type OR page type, so you don't need to create any extra containers below that page unless it is meaningful.

I'm sure you have setup a local Alloy MVC site if not, now is the time to create and look at the StartPage.cs and how the AvailableContentTypes attribute is used on it, you would decorate your "MyPage" with the attribute and use the ExcludeOn property (and would list all the content types that "MyPage" content type should not be available, can get to be a long list :/ ), see documentation (scroll to AvailableContentTypesAttribute title).

Depending how your other content types limit what can be created under those types, you might be able to use the IncludeOn on the "MyPage" type to allow it under the "Secrets" content type BUT if any content type allows All, then your "MyPage" content type would be available there to so you would need to also use the ExcludeOn property. So the answer is that you need to test your types to find the correct definition/combination for AvailableContentTypesAttribute properties ;)

#230097
Edited, Oct 29, 2020 19:36
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.