Jump to:

23576 Posts in 19403 Topics by 2893 members

General Questions

SilverStripe Forums » General Questions » Making Image SRC's Absolute in Body Content

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: 1826 Views
  • entercow
    Community Member
    13 Posts

    Making Image SRC's Absolute in Body Content Link to this post

    Hi Guys,

    I'm trying to make my image tags inside $Content appear with absolute links - so instead of

    <img src='assets/Uploads/img.jpg'>

    I'd like

    <img src='http://www.website.com/assets/Uploads.img.jpg'>

    I was hoping the AbsoluteLinks() function - $Content.AbsoluteLinks - would do this, but it just adjusts the hrefs. Is there a quick and easy way to handle this?


  • Hamish
    Community Member
    712 Posts

    Re: Making Image SRC's Absolute in Body Content Link to this post

    Ironically, the code for Image->getURL() his this comment:

    * @todo Refactor to return absolute URL like {@link File}

    So, at some point this might be fixed. For now, you'll have to write it out in your template, using the base tag and relative url:

    <img src='{$Top.BaseHref}/{$URL}' />

    (Not tested, FYI)

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.