Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Tricky Navigation

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1433 Views
  • Nicko
    Avatar
    Community Member
    14 Posts

    Tricky Navigation Link to this post

    Hi,

    I am transferring an existing static corporate website to Silverstripe. On the homepage the navigation has a group of second level navigation items open while their are other second level nav items which you can't see until you click on the top level link.

    I want to be able to replicate this in SilverStripe and was thinking the best way to do it would be with in IF statement in the template as so:

    <% if Children %>
                   <% if URLSegment="industry-practice">
                   
                   <li class="$URLSegment"><a href="$Link" title="{$Title}" class="$LinkingMode">$MenuTitle</a>
                      <ul>
                      <% control Children %>
                      <li class="$LinkingMode"><a href="$Link" title="{$Title}" class="$LinkingMode">$MenuTitle</a></li>
                      <% end_control %>
                      </ul>
                      </li>
                <% else %>
                   <li class="$LinkingMode"><a href="$Link" title="{$Title}" class="$LinkingMode">$MenuTitle</a></li>

                   <% end_if %>
                <% else %>
                   <li class="$LinkingMode"><a href="$Link" title="{$Title}" class="$LinkingMode">$MenuTitle</a></li>
                <% end_if %>

    Anyway this doesn't work but is it possible to do something like <% if URLSegment="industry-practice"> ? Otherwise is their an easier way to selectively display a second level menu item based on a class?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Tricky Navigation Link to this post

    Maybe you're looking for

    <% if InSection(page-url) %>

    ?

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Tricky Navigation Link to this post

    have a look at -
    http://doc.silverstripe.com/doku.php?id=built-in-page-controls
    http://doc.silverstripe.com/doku.php?id=built-in-page-controls#links_and_class_s

    for a range of things you can do. <% if InSection %> or <% LinkOrSection %> might work well

  • Nicko
    Avatar
    Community Member
    14 Posts

    Re: Tricky Navigation Link to this post

    Thanks both for your help. InSection doesn't seem to work for me. I played around with

    <% if Title=PageTitle %> instead and it worked to a point. First I tried a page with only one word as the title but then I tried the page I wanted called "Industry Practices" and it doesn't work. ie

    <% if Title=Industry Practices %>

    It obviously doesn't like the spacing but I have no idea how to overcome this.

    Any ideas?

    Thanks

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Tricky Navigation Link to this post

    Why doesn't InSection work?

    Or else URLSegment must work.. but remember you shouldn't use quotes, at least that's what the docs say.

    So:

    <% if InSection(industry-practice) %>

    <% end_if %>

    or

    <% if URLSegment = industry-practice %>

    If none is working I think something else might be wrong...

  • Nicko
    Avatar
    Community Member
    14 Posts

    Re: Tricky Navigation Link to this post

    I gave URLSegment a go and it didn't work at first. I then renamed the page URL and it worked? So all is well now.

    Thanks very much for you help.

    1433 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.