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.

Template Questions /

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

How to stop changing in-page bookmark links


Go to End


3 Posts   1804 Views

Avatar
alialamshahi

Community Member, 5 Posts

3 August 2015 at 9:41am

Edited: 03/08/2015 9:42am

Hello everyone,

I have some bookmarks in my page with buttons linking to them, they are defined by a class name which makes a smooth scroll navigating to bookmark. I'm using this piece of javascript:

$(".smooth-scroll").click(function() {
    var onwardId = $(this).attr("href");
    $("html, body").animate({
        scrollTop: $(onwardId).offset().top
    }, "slow");
    return false;
});

But, silverstripe changes my href="#bookmark" buttons to href="baseurl/section/page.html#bookmark" so my script doesn't recognize the bookmark and navigating to bookmark has no smooth scroll effect.

How can I stop SS to do that change? is there any modifications I should do to make the script work?

Thanks in advance.

Avatar
Nightjar

Community Member, 28 Posts

3 August 2015 at 10:58pm

You can do this by configuring the template parser to not rewrite the hash links:
eg. mysite/_config/config.yml:

SSViewer:
  rewrite_hash_links: false

Avatar
alialamshahi

Community Member, 5 Posts

3 August 2015 at 11:12pm

Thanks a million! Works perfect!