Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Get current page with a fixed menu structure?

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: 2698 Views
  • DonL
    Avatar
    Community Member
    9 Posts

    Get current page with a fixed menu structure? Link to this post

    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?

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Get current page with a fixed menu structure? Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Get current page with a fixed menu structure? Link to this post

    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.

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Get current page with a fixed menu structure? Link to this post

    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

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Get current page with a fixed menu structure? Link to this post

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

    MM

  • jamesg
    Avatar
    Community Member
    8 Posts

    Re: Get current page with a fixed menu structure? Link to this post

    You're missing an <% end_if %>

    edit: but you beat me to it

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