spierala
spierala

Reputation: 2699

Silverstripe loop over ALL children of the sitetree

I´m trying to create a sitemap of all children of the sitetree. For some pages ShowInMenus is set to false. But still these pages should be shown in the sitemao. I know you can loop over all children of a page like this (ignoring ShowInMenus):

<% loop AllChildren %>
    $Title
<% end_loop %>

Can I do something similar on the top Level of the sitetree?

Thx, Florian

Upvotes: 1

Views: 2597

Answers (1)

munomono
munomono

Reputation: 1245

i do not know any build in loop you can use for this but you can do in php

public function AllPagesWithParentIDZero() {
    return SiteTree::get()->filter('ParentID', 0);
}

and use in template

<% loop $AllPagesWithParentIDZero %>
    <a href="$Link">$Title</a>
<% end_loop %>

Upvotes: 3

Related Questions