Jump to:

3432 Posts in 1025 Topics by 865 members

Template Questions

SilverStripe Forums » Template Questions » CSS dropdown/if-block

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1027 Views
  • junkbunny
    Avatar
    Community Member
    1 Post

    CSS dropdown/if-block Link to this post

    Hi,

    I'm incredibly new to using Silverstripe so forgive me for anything daft I might say.

    I've been working on a website here: http://dev.whhf.org.nz - putting a CSS drop-down menu on the navigation. It's working fine but the problem is that the code calls the children of each page that's in the nav. If you hover over the 'news' link, a gigantic drop-down list appears because there are hundreds of news items which are children of the news page.

    Is it possible for me to have SS call the children for all the pages EXCEPT 'news' and 'giftshop'?

    Here's the code I currently have in Navigation.ss:

    <ul id="menu">
       <% control Menu(1) %>
           <% if Last %>
              <li class="li-top"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode top sub last" style="margin-left: 0px;">$MenuTitle</a>
             <% if Children %>
                <ul class="leveltwo">
                   <% control Children %>
                      <li><a href="$Link" class="$LinkingMode" title="$Title">$MenuTitle</a></li>
                   <% end_control %>
                </ul>            
             <% end_if %>
             </li>
          <% else %>
             <li class="li-top"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode top sub">$MenuTitle</a>
                <% if Children %>
                   <ul class="leveltwo">
                      <% control Children %>
                         <li><a href="$Link" class="$LinkingMode" title="$Title">$MenuTitle</a></li>
                      <% end_control %>
                   </ul>
                <% end_if %>
             </li>
          <% end_if %>
       <% end_control %>
    </ul>

    Any help will be greatly appreciated. Please try to explain things to me as simply as possible if you can..

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: CSS dropdown/if-block Link to this post

    You could add a <% if ShowSubMenu %> around the <% if Children %> then make a function like this in your Page class in mysite/code/Page.php

    function ShowSubMenu() {
    $ignored = array('news', 'giftshop');

    return (!in_array($this->URLSegment, $ignored));
    }

    In that example I use the URL, but you could use ClassName if they have individual / unique classes. Thats probably safer say if you renamed giftshop later on.

    1027 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.