Limit no of child pages of a certain type

Alan Isaacson asked on July 12, 2016 15:34

I am currently working on a homepage that happily calls in its content from its direct child pages via PagesDataSource and a hierarchical viewer. Currently users can create an unlimited amount of children such as * Text block * Video * Hero block * Map * Image crossfader Is it possible within the hierarchical viewer to say that they can only have 1 hero block per homepage as an example?

By calling the pages in this way it allows for easier manipulation of the order of the page.

Thanks in advance

Recent Answers


Trevor Fayas answered on July 12, 2016 18:23

Slightly confused, hopefully you can clarify. Are you just trying to do a Hierarchy transformation where it only grabs the first "Hero block"?

If so you can set the FirstItem Transformation of it to the actual transformation, and render blanks for the rest, however it may be different if you allow other items (like text blocks, etc) to be siblings of the Hero Block.

Use Parent/Child allowed page types to control the structure on the tree, then use the hierarchy transformer's FirstItem for the Hero block page type...hopefully that points you in the right direction. If not if you could show via bullet list the structure that would help.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 12, 2016 23:26

I agree with Trevor, you can get pretty creative with the Hierarchical transformations. Problem you run into sometimes is issues where maybe the Hero isn't the first item in the list so you need to setup First item transformations for the other objects as well. But this would be where I'd start otherwise you'd have to create a pretty custom query I believe.

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on July 13, 2016 14:14

Hi both, Many thanks for the answers. Here is a copy of the current page tree Image Text Basically the Home page has a hierarchical viewer that calls in each child page in NodeOrder. This means that it will be easier for our customers to simply build a page by block type and then reorder within the tree. This means that the hero block could be anywhere within the order of child pages.

This means that the Home page will allow any of the 5 child types. I would like to be able to say that either a) The homepage will only ever call in 1 hero block (probably the first it encounters) or b) The homepage will only allow 1 hero block child to be created.

I am hoping that we can achieve this with Kentico directly as our learning curve is still not at the custom query end of the curve.

Hope that helps to make it clearer.

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on July 13, 2016 14:16 (last edited on July 13, 2016 14:16)

The image should have been here

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on July 15, 2016 15:03

If i'm undestanding, the hero block can be at any level, and you only want 1 to be allowed.

So in the case you have a hero block at level 1, and a hero block somewhere at level 2, you still only want the level 1 to show.

If you have hero blocks only at level 2, it should only show the first.

The only way i can think to do this is either through updating a macro/session value during the transformations (something like "If(IsHero && !HeroUsedAlready) { do transformation, set HeroUsedAlready to true } else { do nothing })

But this is still more advanced, i can kind of guide you on it but first confirm this is the situation, the tree helped but i didn't see any hero blocks labeled in it.

0 votesVote for this answer Mark as a Correct answer

Alan Isaacson answered on July 15, 2016 15:48

Thanks Trevor, the idea would be that Home would only call in one Hero block from a direct child. Now of the other sub pages are allowed to have Hero block as a child. So if someone added a child to home of Hero Block I would not want then to be able to call in a 2nd one even if they have created one. I am using Hero Block as an example but it could as easily be that the Images Block is only allowed to be used once, as the logic would be the same regardless.

The content is called into the Home page and uses a hierarchical transformation so (something like "If(IsHero && !HeroUsedAlready) { do transformation, set HeroUsedAlready to true } else { do nothing }) would probably do what I need.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.