Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » Stop Silverstripe from modifying href attributes

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

Page: 1
Go to End
Author Topic: 8421 Views
  • Iain_vdw
    Avatar
    Community Member
    22 Posts

    Stop Silverstripe from modifying href attributes Link to this post

    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.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

    > 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 http://dev.jqueryui.com/ticket/3527). Perhaps try raising this again on http://dev.jqueryui.com/newticket ? I've tried to fix it a while ago, but its a bit tricky to wrangle all W3C allowed URLs with regular expressions etc.

  • Iain_vdw
    Avatar
    Community Member
    22 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

    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
       for(i=1;i<=3;i++){
          // 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.

  • guillaume
    Avatar
    Community Member
    7 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

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

    http://dev.jqueryui.com/ticket/4941

    BR, Guillaume.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

    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?

  • obj63mc
    Avatar
    Community Member
    24 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

    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?

    Thanks
    Joe

  • Ricardona
    Avatar
    Community Member
    26 Posts

    Re: Stop Silverstripe from modifying href attributes Link to this post

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

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