4

I'm trying to limit editors to create wrong document on Kentico nodes. I know there is Page Types -> Scopes for this, but in my case it is hard to configure it. In my scenario I have a repeated node structure like this:

Root (template: ROOT)
  - Page 1 (type: Page; template: PAGE)
  - Page 2 (type: Page; template: PAGE)
  - Page 3 (type: Page; template: PAGE)
  ...
  - Section A (type: Page; template: SECTION)
    - Node 1 (type: Page; template: NODE)
    - Node 2 (type: Page; template: NODE)
    - Node 3 (type: Page; template: NODE)
    ...
  - Section B (type: Page; template: SECTION)
    - Node 1 (type: Page; template: NODE)
    - Node 2 (type: Page; template: NODE)
    - Node 3 (type: Page; template: NODE)
    ...
  - Section C (type: Page; template: SECTION)
    - Node 1 (type: Page; template: NODE)
    - Node 2 (type: Page; template: NODE)
    - Node 3 (type: Page; template: NODE)
    ...

Editor could create a lot of sections, but always with the SECTION template. I want that under a Section an editor can create only a Node of type "PAGE".

This is what I'm trying to do: I create a new Macro rule (on Macro rules application) that check if current page has a specific template (passed on parameters) see image

Then I create a new Scope (Page Type -> Scopes) see image

I think it was all ok (on "Section A" I can add only "Page" documents), but also in "Page 1" (with template different from SECTION) I can add only "Page" documents. It seems that my condition return always "true"

I try to change the parameter field in my Macro with "DocumentPageTemplateID" against "NodeTemplateID", but I have the same result.

I believe to be close to the solution. Can you help me?

PS: I know that I can create a different page type for Section A, B, C and then use the Page Type Scopes, but I prefer to do this in base of the Template instead of Type.

Thank you

Alberto
  • 71
  • 1
  • 7
  • Alberto, how deep can this structure go? Does it only adhere to the levels that you have indicated in the example above? (ignore me if this is no longer relevant ) – mnield Oct 03 '17 at 19:28
  • I solve this with the workaround at the end of this post (see my last answer), but if you have any suggestion... wow! "how deep can this structure go?" more deep it goes, better it is :-) Share your idea – Alberto Oct 05 '17 at 06:47

3 Answers3

7

Instead of using the Page page type for a 'Section', create a new Section page type and set the default template for it. Then maybe create another new page type called 'Node' and set a default template for it as well. No need to get crazy with scopes, just set the scope for both the Section and Node page types to be at the root and only allow Nodes to be placed below Sections and Sections can only be placed below the Root document.

Brenden Kehren
  • 5,919
  • 16
  • 27
  • Here is the documentation on creating Parent-Child relationship for page type in case you are interested: https://docs.kentico.com/display/K9/Setting+parent-child+relationships+for+classes – Rui Aug 03 '16 at 20:27
  • Hi all and thanks. I know that with different Page Type I can do this. I was courios to do this with the template used. I don't understand why my condition return always true. – Alberto Aug 04 '16 at 06:43
  • According to your macro condition - can you check macro debug? – Martin Makarsky Aug 04 '16 at 09:27
  • @martin. Thank you, I didn't know about the Macro Debug. I'm trying it and it seems that the CurrentDocument in the UI is null. I have to access the clicked document and check the TemplateID. I keep trying... – Alberto Aug 04 '16 at 14:22
  • CurrentDocument only works outside the Admin UI. If you need the current document in the Admin UI use EditedDocument instead. – Brenden Kehren Aug 04 '16 at 14:24
  • Shoot sorry, typo in my end, should be EditedObject, not EditedDocument. – Brenden Kehren Aug 04 '16 at 14:44
  • @BrendenKehren Thank you, but also EditedObject is null... I'm trying with System.GetObject(...) ([link](http://devnet.kentico.com/questions/kentico-8-how-to-introduce-a-custom-edit-tab,-visible-only-when-a-document-based-on-a-specific-doc-type-is-selected-in-the-tree)) – Alberto Aug 04 '16 at 14:53
1

Just for your information, it is possible to set allowed child and parrent page types which could be pretty suitable for your scenario. Just check docs.

Edit: According to Page templates - in Page templates app there is possibility to limit creating a page with page template on the certain path (see attachment bellow). You can learn more here.

enter image description here

Martin Makarsky
  • 2,580
  • 1
  • 17
  • 28
  • Thank you @martin. Yes, this can be done with the Page Types definitions. My approach was to find a way to limit the child types based on the template of the parent node. – Alberto Aug 04 '16 at 07:57
  • If I have understand right, with your answer I can limit to create a page with a determinate template. For example I can set that the template SECTION could be assigned to a page only in the 1st level, the template NODE only in 2nd level... But this is not the solution to my answer (maybe I don't understand). My goal is when I right-click on node SECTION A and press the menu item "NEW..." the only page types document allowed are "Page (Menu Item)". But if I right-click on node PAGE 1 (same type and level of SECTION A) and press NEW... I want to be able to add other docs – Alberto Aug 04 '16 at 13:28
0

I found a workaround. I post it to anyone that want to do this (and help me to complete it :-) ).

I change the Macro condition with this:

{_is}(Documents.Where("NodeID=" + QueryString.parentnodeid)[0].DocumentPageTemplate.CodeName == "{template}")

Then I create the Scope using this condition.

When I click in the NEW function of a node the page loaded show me only the desired Page Type (selected in the Scope). This works because when I click on NEW button Kentico load this page: /CMSModules/Content/CMSDesk/New/New.aspx?classid=true&parentnodeid=35&parentculture=it-IT where parentnodeid is the Node selected when you ask to add a new Node. I use this parameter to get the document and check the template.

The "problem" of this solution is this: If I right-click the node and choose New... the popup menu will show with all Page Types. It is obvious because the popup menu doesn't call any page so there is no parentnodeid to look for.

At the moment this solution is ok for me, because I told to the site's editors to click on the PLUS button when they want to add a new page.

Thank you all for your help, and I hope we'll find a 100% working solution.

Alberto
  • 71
  • 1
  • 7