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.

General Questions /

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

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

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


Reply


5 Posts   1266 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