Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

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

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

Tricky Navigation


Reply


6 Posts   1518 Views

Avatar
Nicko

Community Member, 14 Posts

5 July 2008 at 3:37am

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?

Avatar
dio5

Community Member, 501 Posts

6 July 2008 at 10:29am

Maybe you're looking for

<% if InSection(page-url) %>

?

Avatar
Willr

Forum Moderator, 5513 Posts

6 July 2008 at 1:08pm

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

Avatar
Nicko

Community Member, 14 Posts

8 July 2008 at 10:02pm

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

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 10:12pm

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

Avatar
Nicko

Community Member, 14 Posts

8 July 2008 at 10:25pm

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.