Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

How to test for Children()

$
0
0

I have this function in a custom page_controller to work out how many "columns" of display items I have for css purposes. Its children with published children.

The problem is that $child->Children() returns an arraylist and therefore effectively true even when there are no published items and the printing sub-loop returns null.

As a result the count is wrong. I also use <% if Children %> in my templates.

Is there an alternative function?

public function columnCount(){
$count = 0;
if($this->Children()){
foreach($this->Children() as $child){
if($child->Children()){
$count++;
// following 4 lines just for test
foreach($child->Children() as $mokopuna){
print_r("Child name: ");
print_r($mokopuna->URLSegment.' - '.$mokopuna->URLSegment);
print_r("<BR>");
}
}
print_r("<hr>");
}
};
return $count;
}


Posted to: How to test for Children() | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles