如何仅遍历SilverStripe中的所有隐藏页面?
$ Children 排除隐藏页面。 $ AllChildren 包含所有网页。有没有办法只包含隐藏的页面?
答案 0 :(得分:4)
我们可以编写一个函数来仅返回隐藏的子元素:
public function HiddenChildren() {
return $this->AllChildren()->filter('ShowInMenus', false);
}
然后在我们的模板中,我们可以像这样循环隐藏的孩子:
<% loop $HiddenChildren %>
$Title
<% end_loop %>
答案 1 :(得分:3)
嗯,模板中的简单if可能会起到作用:
<% loop $AllChildren %>
<% if not $ShowInMenus %>
$Title
<% end_if %>
<% end_loop %>
请参阅https://docs.silverstripe.org/en/3.1/developer_guides/templates/syntax/#negation