Silverstripe 从指定pagetype父级的所有子级创建导航
我正在创建一个带有持有者页面的站点,我想为这个和所有子站点创建一个共享导航树。我提出了一个相当丑陋的解决方案,不知道是否有人有更好、更干净的解决方案 据我所知,有一个模板方法叫做“instation”,但我相信它只匹配指定的页面,而不是页面类型Silverstripe 从指定pagetype父级的所有子级创建导航,silverstripe,Silverstripe,我正在创建一个带有持有者页面的站点,我想为这个和所有子站点创建一个共享导航树。我提出了一个相当丑陋的解决方案,不知道是否有人有更好、更干净的解决方案 据我所知,有一个模板方法叫做“instation”,但我相信它只匹配指定的页面,而不是页面类型 <% with $Level(3) %> <% if $className == "fooHolder" %> <% with $Up %> <article>
<% 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 %>
$Content
$Content
我想出了一个更好的解决方案,但我一直很想再听到更多
在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 %>
$Content
$Content
在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>