Jump to:

23373 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Questions: Print Level Number, Child of Children...

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

Page: 1
Go to End
Author Topic: 1165 Views
  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Questions: Print Level Number, Child of Children... Link to this post

    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

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Questions: Print Level Number, Child of Children... Link to this post

    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++;
          }

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Questions: Print Level Number, Child of Children... Link to this post

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

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Questions: Print Level Number, Child of Children... Link to this post

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

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

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

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Questions: Print Level Number, Child of Children... Link to this post

    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

    1165 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.