How can I access the children of a Silverstripe Page in the Page's controller?

StackOverflow https://stackoverflow.com/questions/22467553

  •  16-06-2023
  •  | 
  •  

Pregunta

I'm working with Silverstripe and I'm trying to find out how many children a page has. How could I best do this from the Page_Controller class?

What I'm looking to do is to calculate the height that a navigation DIV in my template should be based on the number of children that it has to display. So I'm looking to right a function that returns [# of Children] * [Height per Child].

Can anyone advise me how I could go about getting # of children to a Page object?

¿Fue útil?

Solución

ArrayList has a count() function that will return you the number of items in the list.

You can call count() on your page Children list.

$this->Children()->count();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top