Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » How to remove protocol and host in template

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 480 Views
  • Tim Snadden
    Avatar
    Community Member
    32 Posts

    How to remove protocol and host in template Link to this post

    Does anyone know how to prevent silverstripe (2.4) outputting the protocol and host when linking to internal assets etc?

    In the markup I am getting:

    <script type="text/javascript" src="http://my.exampledomain.com/mysite/app/router.js?m=1340064453"></script>

    and I want just:

    <script type="text/javascript" src="/mysite/app/router.js?m=1340064453"></script>

    The reason is that requests are going through a proxy so requests to https://localhost:8000/ are being proxied to http://my.exampledomain.com/ so I don't want http://my.exampledomain.com/ in the markup.

    I've had a look around in Director and tried a few things including:

    Director::setBaseURL('/');

    Any ideas?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: How to remove protocol and host in template Link to this post

    Taking a look at the code it looks like this is hard coded to being absolute. In the Requirements_Backend::path_for_file() class you would need to replace the prefixed value. Patches welcome to make this more accessible.

  • Tim Snadden
    Avatar
    Community Member
    32 Posts

    Re: How to remove protocol and host in template Link to this post

    Thanks for looking at it. I ended up modifying the path_for_file function in core/Requirements.php as follows:

    // $prefix = Director::absoluteBaseURL();
    $prefix = Director::baseURL();

    I would rather not have modified the framework and I guess I was looking for a javascripty way of overriding the function but it doesn't seem like PHP works this way from what I can see.

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