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.

General Questions /

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

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

Making Image SRC's Absolute in Body Content


Go to End


2 Posts   2995 Views

Avatar
entercow

Community Member, 13 Posts

1 October 2009 at 8:27am

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?

Thanks!

Avatar
Hamish

Community Member, 712 Posts

1 October 2009 at 10:10am

Edited: 01/10/2009 10:10am

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)