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.

Content Editor Discussions /

Forum for content editors and CMS users.

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

Base tag and anchors within page incompatible


Go to End


5 Posts   8209 Views

Avatar
michaek

Community Member, 7 Posts

28 October 2009 at 6:29am

Howdy. I'd like to point out that the <base> tag and anchors within pages don't play well together. Because the base tag is set, anchors with href="#" point to siteroot# rather than currentpage#

I can't think of a way to resolve this without hard-coding a path within image tags (making the base tag unneccessary) or within links to anchors (relative to the base tag). The second is probably cleaner.

Avatar
Samba Sam

Community Member, 85 Posts

20 November 2009 at 4:24pm

Edited: 20/11/2009 5:44pm

Hi,
I am running into the same issue. I am currently adapting jquery Galleriffic slideshow to work with Image Gallery.
It references its navigation/pagination of images href="#" in Javascript file. However, because of the base tag, I am taking to the home page instead of the next set of images on the same page when I click the navigation "next" above the images.
Normally, SilverStripe will automatically append the page name to any fragment links, links with "#", in a template. But it doesn't appear to do so when javascript is used to create the href="#" links that actually don't appear in the source code.

For example,
I want the link to point to http://holybasil.info/gallerifficpage/#image,
not http://holybasil.info/#image.

If I remove the base tag, all is well with the slideshow navigation, but not my template, particularly logging in to the admin.
As Michaek has asked, is there a simple way of doing this without, in my case, going into the javascript to make the anchors
relative to the base tag. Something, I don't know how to do at this time.

Thanks,
Sam

Avatar
brokemeister

Community Member, 30 Posts

21 November 2009 at 3:46am

Hi!

You can add function like this
public function BaseTag() {
return '<base href="'. Director::absoluteBaseURL() . '" />';
}
instead of <% base_tag %> to you Page-Controller

You can add any condition (e.g. empty URLSegment) to it, so the login and backend is still working.

In the frontend image-pathes must be absolute.

Cheers,

Malte

Avatar
Samba Sam

Community Member, 85 Posts

22 November 2009 at 3:45am

Edited: 22/11/2009 3:47am

Thanks Malte!
Fairly easy solution.

I replaced <% base_tag %> with $BaseTag in my main Page.ss

I put
public function BaseTag() {
return '<base href="'. Director::absoluteBaseURL() . '" />';
}

into my Page.php

and
public function BaseTag() {
return;
}

in my GallerifficPage.php to remove the base tag in my GallerifficPage.ss so that the gallery slideshow would work.

Though, I did want to make my Galleriffic extension module not require any template editing
for installing. But I guess, unless I am willing to go through the Galleriffic's javascript, this looks like the solution.
I am curious to hear of any other easy possibilities that avoid having to edit templates.

Cheers,
Sam

Avatar
DsX

Community Member, 178 Posts

6 January 2011 at 11:03am

Another method:

add to your Page_Controller in page.php

public function getFullURL(){
return ($_SERVER['REQUEST_URI']);
}

and then use in template as: <a href="{$getFullURL}#top">Top</a>

of course you need to name the anchor somewhere in your template as well.

This method allows you to leave your Base tag alone, which allows you to reference all media (css, js, image etc) as /path