从指定页面类型父级的所有子级创建导航

Create navigation from all children of specified pagetype parent

我正在创建一个带有持有者页面的站点,我想为这个和所有子项创建一个共享的导航树。我想出了一个相当丑陋的解决方案,想知道是否有人有更好、更清洁的解决方案?

据我所知,有一个名为 'InSection' 的模板方法,但我相信这只匹配指定的页面,而不匹配页面类型。

<% with $Level(3) %>
    <% if $className == "fooHolder" %>
        <% with $Up %>
        <article>
            <nav id="contentNav">
                <ol>
                    <% with $Level(3) %><li><a href="$Link" title="$Title.XML">$MenuTitle.XML</a><% end_with %>
                        <% if $Menu(4) %>
                        <ol>
                            <% loop $Menu(4) %>
                                <li class="$LinkingMode"><a href="$Link" title="$Title.XML">$MenuTitle.XML</a>
                                    <% if $Children %>
                                        <ol>
                                        <% loop $Children %>
                                            <li class="$LinkingMode"><a href="$Link" title="$Title.XML">$MenuTitle.XML</a>
                                        <% end_loop %>
                                        </ol>
                                    <% end_if %>
                                </li>   
                            <% end_loop %>
                        </ol>
                        <% end_if %>
                    </li>
                </ol>               
            </nav>
            <section class="article-wrapper">
                $Content
            <section>
        </article>              
        <% end_with %>  
    <% else %>
        <% with $Up %>
               $Content
        <% end_with %>
    <% end_if %>
<% end_with %>

我想出了一个更好的解决方案,但总是有兴趣听到更多。

在Page.php

public function parentFromPageType($pageType){

    if ($this->ClassName == $pageType) {
        $sectionRoot = $this;
    } else {
        $sectionRoot = $this->getAncestors()->filter(array(
            'ClassName' => $pageType
        ));
    }

    if ($sectionRoot ) {
        return $sectionRoot ;
    } else {
        return false;
    };
}

在Page.ss

<% if $parentFromPageType(CategoryIntroPage) %>
    <article>
        <nav id="contentNav">
            <ol>
                <% loop $parentFromPageType(CategoryIntroPage) %>
                    <li><a href="$Link" title="$Title.XML">$MenuTitle.XML</a>
                        <% if $Children %>
                            <% include NestedChildren %>
                        <% end_if %>
                    </li>   
                <% end_loop %>
            </ol>
        </nav>
        <section class="article-wrapper">
            $Content
        <section>
    </article>  
<% else %>
    $Content
<% end_if %>

在Includes/NestedChilden.ss

    <ol>
        <% loop $Children %>
            <li class="$LinkingMode"><a href="$Link" title="$Title.XML">$MenuTitle.XML</a>
                <% if $Children %>
                    <% include NestedChildren %>
                <% end_if %>
            </li>                       
        <% end_loop %>
    </ol>
</li>