Silverstripe Menu, Submenu, and Breadcrumbs

非 Y 不嫁゛ 提交于 2019-12-11 04:29:43

问题


How do I change the default Silverstripe theme 'Simple' so that when a submenu (on the sidebar) is clicked the sidebar menu is replaced by a breadcrumb via $Breadcrumbs. Example when Menu1 is clicked, the sidebar is shown

       Menu1   Menu2    Menu3

Menu1 (not clickable, just a title) SubMenu1 SubMenu2

but when either SubMenu1 or SubMenu2 is clicked entire sidebar dissapears and a $Breadcrumbs is shown.

       Menu1   Menu2    Menu3

Menu1-->SubMenu1 $Content

Therefore when Menu1 on Breadcrumb is clicked, it goes back to Menu1.


回答1:


First of all, why do you want to achieve this? I can't see a real benefit out here, but if you really need this, so this could be possible an answer:

1) If you are on the $Menu(1) level show only $MenuTitle.XML (or just $Title, they're almost the same)in the sidebar

2) Else If you are on the $Menu(2) or deeper than (2) level show breadcrumbs

You could achieve this by checking on which level you are at the moment and display what you need:

<% if $Menu(1) %>
  <!-- Here you print only titles-->
  <% loop $Menu(1) %>
    <a href="$Link">$MenuTitle.XML</a>
  <% end_loop %>
<% else %>
  <!-- Here you print out the BreadCrumbs, only if you are deeper than 1st level menu -->
  <% include $BreadCrumbs %>
<% end_if %>

Here you check if you are on first level then display only titles with links, then if you are on the subpage display the BreadCrumbs



来源:https://stackoverflow.com/questions/32275284/silverstripe-menu-submenu-and-breadcrumbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!