为此有一个内置的页面控件,因此要从列表中排除当前页面:
<% control ChildrenOf(page-url) %>
<% if LinkOrCurrent = current %>
<!-- exclude me -->
<% else %>
<!-- Output some stuff, like the page's $Link and $Title -->
<% end_if %>
<% end_control %>
请参阅http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls#linkingmode-linkorcurrent-and-linkorsection
更新
正如您在下面的评论中提到的,您想使用 $Pos 控件,您需要在迭代之前过滤数据对象集。将以下内容添加到您的 Page_Controller 类中:
function FilteredChildrenOf($pageUrl) {
$children = $this->ChildrenOf($pageUrl);
if($children) {
$filteredChildren = new DataObjectSet();
foreach($children as $child) {
if(!$child->isCurrent()) $filteredChildren->push($child);
}
return $filteredChildren;
}
}
然后用“FilteredChildrenOf”替换模板中的“ChildrenOf”:
<% control FilteredChildrenOf(page-url) %>
//use $Pos here
<% end_control