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.

Template Questions /

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

Stop Silverstripe from modifying href attributes

Go to End

7 Posts   10667 Views


Community Member, 22 Posts

28 October 2009 at 10:24pm

Edited: 28/10/2009 11:37pm

Hi there,

I've got a weird problem. When there's a <a href="#somethinghere"> tag present in the template, and visting a page with parameters in the url (i.e. /page/?foo=bar), SilverStripe adds the parameter part to the anchor tag. This in turn causes a javascript to break which is dependant on the content of the href part.

To show the example:

code on /page/

<a href="#tabs-1">

code on /page/?foo=bar

<a href="?foo=bar#tabs-1">

This behaviour causes Silverstripe to break the javascript and for some weird reason loads the templates TWICE! The #tabs-1 is part of the functionality of the jQuery UI Tabs addon.

Is there a way to stop SilverStripe from adding the parameter part to the <a href=""> ?

I already have

SSViewer::setOption('rewriteHashlinks', false);
active to stop Silverstripe from adding slashes to url's.

Help is much appreciated!

Edit: I seem to know what happens now. It doesn't break the javascript, but causes it to think i'm loading content into the tabs via Ajax. Because of the added parameter to the href tag, it thinks it's another url instead of the id of the tab. And that it shouldn't do, unless I tell it to.

Edit 2: Seems this is a conflict of functionalites of JQUI Tabs and Silverstripe. Silverstripe uses the base tag, so it *needs* to add the $URLSegment of the page before the anchor to make it navigate correctly. Then the JS "detects" a page url instead of an anchortag so it then loads the corresponding page into the displayed tab.

Guess i need to alter the JS to let it respond to something else, like title="#tabs-1" i guess.


Forum Moderator, 801 Posts

2 November 2009 at 9:12am

> Then the JS "detects" a page url instead of an anchortag so it then loads the corresponding page into the displayed tab.

This is a but in JQuery UI Tabs, it doesn't take the <base> into account when auto-detecting URLs that are not pointing to the current page.

Sadly there is no way to disable remote tabs (see Perhaps try raising this again on ? I've tried to fix it a while ago, but its a bit tricky to wrangle all W3C allowed URLs with regular expressions etc.


Community Member, 22 Posts

2 November 2009 at 10:38pm

Edited: 02/11/2009 10:40pm

Hey Ingo,

Thx for your reply, but i fixed it already. I used a custom jquery script to target the href attribute of those <a> elements to reset the attribute to the wanted setting and it worked :)

This is the script i made:

jQuery(document).ready( function(){
	// Count till 3 for the 3 tabs
		// Target tabs and modify attribute
		jQuery('#actierotator #acties li a.tabs-'+i).attr('href','#tabs-'+i);

This overrides the generated code and "corrects" the behaviour to what i want it to do.

And if JS is disabled, it degrades gracefully.


Community Member, 7 Posts

18 December 2009 at 7:37am

Hi there,
i found a ticket that does the trick.

BR, Guillaume.


Forum Moderator, 801 Posts

18 December 2009 at 8:56am

Ah good find Guilllaume! I was trying to patch this myself a while ago, its very annoying... lets hope jQuery UI 1.8 comes out soon ;) Hows things going in Stockholm?


Community Member, 25 Posts

28 January 2010 at 1:23pm

Hi There,

I am having a problem with this as well where I will write out links such as <a href="$Link" title="Go to page $PageNum">$PageNum</a>

The problem is if there is a query string it is randomly appended to $Link or even inside some html content sections.

I can't find a common theme too as to when this happens versus when it doesn't happen as it doesn't do it to every link in the page just random ones.

Any idea how to have this stop or remove it manually with a function or on the template?



Community Member, 26 Posts

5 May 2010 at 2:55pm

JQuery 1.8 not fix the error, you need change the js for fix it. :(