Jump to:

520 Posts in 248 Topics by 263 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » Base tag and anchors within page incompatible

Forum for content editors and CMS users.

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

Page: 1
Go to End
Author Topic: 4382 Views
  • michaek
    Avatar
    Community Member
    7 Posts

    Base tag and anchors within page incompatible Link to this post

    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.

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Base tag and anchors within page incompatible Link to this post

    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

  • brokemeister
    Avatar
    Community Member
    30 Posts

    Re: Base tag and anchors within page incompatible Link to this post

    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

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Base tag and anchors within page incompatible Link to this post

    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

  • DsX
    Avatar
    Community Member
    178 Posts

    Re: Base tag and anchors within page incompatible Link to this post

    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

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