Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Questions: Print Level Number, Child of Children...


Go to End


5 Posts   1628 Views

Avatar
biapar

Forum Moderator, 435 Posts

4 December 2009 at 12:43am

Edited: 04/12/2009 11:04am

Hi,

1) How can I print "Level" number or actual deep?

2) I'm into a page with at X. Then I need info from of object from first child of each childreon of page at level X ...

Page Level X / Children / 1st Child

Thank you

Avatar
dalesaurus

Community Member, 283 Posts

4 December 2009 at 11:54am

You can just do manual counts if it would be more efficient, here is an example for use in a controller function (ie control):

		$item = $this->dataRecord;
		$level = 0;
		// 10 is just a limit to prevent endless loops, increase as needed
		while($item && $level < 10) {   
			$item = $item->Parent;
			$level++;
		}

Avatar
biapar

Forum Moderator, 435 Posts

4 December 2009 at 7:48pm

thank for your reply. This in an answer for point 1). And for 2)?

Avatar
dalesaurus

Community Member, 283 Posts

5 December 2009 at 4:04am

Ah, sorry about that. Silverstripe's Hierarchy provides this:

Model:
$firstChild = $this->Children()->First();

Controller:
$firstChild = $this->dataRecord->Children()->First();

Avatar
biapar

Forum Moderator, 435 Posts

16 December 2009 at 4:49am

Edited: 16/12/2009 4:49am

Hi,

I resolved question 2 with:

<% control Children %>
<% control Children %>
											    
										
		<% if First %>
		<div class="fright-imm-prod-table alignright">
                                                <a href="$Link" >$Image1.Thumbnail</a>
                 </div>
											 
		<% end_if %>
											
<% end_control %>
<% end_control %>

Bye