【问题标题】:Silverstripe loop over ALL children of the sitetreeSilverstripe 循环遍历站点树的所有子节点
【发布时间】:2013-02-16 22:25:01
【问题描述】:

我正在尝试为站点树的所有子项创建站点地图。对于某些页面 ShowInMenus 设置为 false。但是这些页面仍然应该在sitemao中显示。我知道你可以像这样遍历页面的所有子页面(忽略 ShowInMenus):

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

我可以在站点树的顶层做类似的事情吗?

谢谢, 弗洛里安

【问题讨论】:

    标签: content-management-system silverstripe


    【解决方案1】:

    我不知道你可以使用任何内置循环,但你可以在 php 中做

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

    在模板中使用

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

    【讨论】:

    • 感谢 ajshort 清理它 - 我发布答案时已经晚了。
    • 可以,只是需要过滤掉ErrorPages,我可以很快检查。谢谢
    • foreach(SiteTree::get()->filter('ParentID', 0) as $RootPage),正是我需要的,谢谢@munomono
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 2015-01-19
    • 2013-09-13
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    相关资源
    最近更新 更多