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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
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++;
}
thank for your reply. This in an answer for point 1). And for 2)?
Ah, sorry about that. Silverstripe's Hierarchy provides this:
Model:
$firstChild = $this->Children()->First();
Controller:
$firstChild = $this->dataRecord->Children()->First();
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