Jump to:

23363 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Trailing slash in menu links

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1562 Views
  • Vinnie
    Avatar
    Community Member
    2 Posts

    Trailing slash in menu links Link to this post

    I've searched the forum a few times now but can't find the answer what i'm looking for..

    Why does SilverStripe add a trailing slash at the end of menu links?
    Is it necessary and can it be removed? If so, how?

  • Vinnie
    Avatar
    Community Member
    2 Posts

    Re: Trailing slash in menu links Link to this post

    no one?
    there must be some reason why links end with a slash and somehow it has to be possible to remove those 'trailing slashes' in (menu)links..

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: Trailing slash in menu links Link to this post

    I think if you gave a more two-year-old description with a screen print, a code fragment or one of the "menu links" you are talking about I might have answered - but as it is I really don't understand what it is...

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Trailing slash in menu links Link to this post

    Vinnie, the slash is added in SiteTree::RelativeLink($action), which is called by SiteTree::Link($action), in the return statement:

    return Controller::join_links($base, '/', $action);

    While the slash is not needed (you can try it by removing the trailing / from any of your URLs), it can't be easily removed while keeping the upgrade process simple.

  • neilcreagh
    Avatar
    Community Member
    90 Posts

    Re: Trailing slash in menu links Link to this post

    Hi Vinnie,

    I stumbled across this post because I was having trouble linking to a dataobject because of the slash being added. I was doing something like this:

    $Link/show/$ID

    But instead you can customise the Link() method on the data object itself (or page class) - and then just use $Link

    I found this solution posted by Uncle Cheese on this post:

    function Link()
    {
    return $this->Page()->Link("show")."/".$this->ID;
    }

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