Reputation: 40499
I'm putting together a 3 tier navigation menu in a SilverStripe 3.1 template, and have the following code in my template:
<% loop $Menu(1) %>
...
<% loop $Children %>
...
<% loop $Children %>
<li><a href="$Link">$Model</a></li>
<% end_loop %>
<% end_loop %>
<% end_loop %>
However I'm not getting the output I expect from the 3rd tier. Is it actually possible to get the Children of the Children? If not, then what should I do instead? Thanks!
Upvotes: 1
Views: 1339
Reputation: 15794
Yes it is possible to loop through the Children of a Children loop.
Your code looks correct to me. It should work correctly.
Here are a few possible issues to check.
Make sure all the pages at each level have ShowInMenus
set to true. $Children
and $Menu(1)
only returns pages that have ShowInMenus
set to true. This checkbox can be found in the Settings tab of any page. Otherwise you can use $AllChildren
instead of $Children
to get hidden pages as well.
Make sure the site tree has pages that are 3 levels deep. An obvious thing to check.
$Model
is not an in built page variable. This must a custom variable you have set. Make sure this is set to the Page, has values filled in and is accessible on the front end.
Here is some test template code you can use to check the output of your site tree. This may help you in debugging your problem:
<ul>
<% loop $Menu(1) %>
<li>
<a href="$Link">$Title - $Model</a>
<% if $Children %>
<ul>
<% loop $Children %>
<li>
<a href="$Link">$Title - $Model</a>
<% if $Children %>
<ul>
<% loop $Children %>
<li>
<a href="$Link">$Title - $Model</a>
</li>
<% end_loop %>
</ul>
<% end_if %>
</li>
<% end_loop %>
</ul>
<% end_if %>
</li>
<% end_loop %>
</ul>
Upvotes: 3