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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Get current page with a fixed menu structure?


Go to End


6 Posts   3733 Views

Avatar
DonL

Community Member, 9 Posts

12 August 2008 at 8:15am

I'm new to SS and working on converting an existing site for use with the CMS. The site design involves a graphical menu bar across the top which uses separate images for each menu item. For simplicity's sake I'm inclined to leave it this way (at least for now) and just change the links to point to the relevant SS top-level pages. However, I need to be able to figure out which menu item is the current page and display a different image in the menu bar. Currently this is done by simply having a different HTML file for each page and hard-coding the images, but obviously I don't want to do that.

The <% if LinkCurrent = current %> doesn't seem to work without the SS menu control structure, so is there some other way to do this?

Avatar
Fuzz10

Community Member, 791 Posts

12 August 2008 at 8:56am

You can use $URLSegment, this returns the part of the url of the page you are on. You could also add a custom identification field to your pageclass and use that to identify the current page.

Avatar
Willr

Forum Moderator, 5523 Posts

12 August 2008 at 9:02am

if I have to do a site with graphical navigation what I normally do is in the menu control (nice bits cut out for briefness)

<% control Menu(1) %>
<img src="{$URLSegment}nav.gif" alt="$Title" />
<% end_control %>

So if you have a Blog page with a URL of blog your blog image should be blognav.gif and blognavCurrent. Then what you could do if you want to swap the images on the current page is

<% control Menu(1) %>
<% if LinkOrSection = section %>
<img src="{$URLSegment}navCurrent.gif" alt="$Title" />
<% else %>
<img src="{$URLSegment}nav.gif" alt="$Title" />
<% end_control %>

Thats just one of the ways you could do it.

Avatar
mschiefmaker

Community Member, 187 Posts

12 November 2008 at 9:45am

When I use

<% control Menu(1) %>
<% if LinkOrSection = section %>
<img src="/themes/purplewine/images/menu/{$URLSegment}nav.gif" alt="$Title" />
<% else %>
<img src="/themes/purplewine/images/menu/{$URLSegment}navCurrent.gif" alt="$Title" />
<% end_control %>

The website returns a blank screen. I can save in the CMS with no errrors.

<% control Menu(1) %>
<img src="/themes/purplewine/images/menu/{$URLSegment}nav.gif" alt="$Title" />
<% end_control %>

Works fine.

The problem seems to be caused when I add <% if LinkOrSection = section %> but I can see nothing wrong with this syntax and I am getting no error messages. Am new to this so it might be something obvious. Would appreciate any suggestions

MM

Avatar
mschiefmaker

Community Member, 187 Posts

12 November 2008 at 10:15am

Ignore this question ... must be a newbie error. All working fin now.

MM

Avatar
jamesg

Community Member, 8 Posts

12 November 2008 at 10:16am

Edited: 12/11/2008 10:17am

You're missing an <% end_if %>

edit: but you beat me to it :P