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.

Themes /

Discuss SilverStripe Themes.

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

Creating portable links


Go to End


4 Posts   2327 Views

Avatar
thepurpleblob

Community Member, 28 Posts

3 November 2009 at 11:31pm

I am developing a new theme with some images in it. What I need to do is to include img tags to images that are located in a sub-directory of the theme.

I need the theme to be portable but I'm unsure how to specify the URL of the image. It's easy enough if the silverstripe install will always be at the top level, but it won't. Is there a variable I can access in the template to specify the 'root' of the install or is there a simpler and/or more sensible way to do this?

Avatar
bummzack

Community Member, 904 Posts

4 November 2009 at 2:55am

You can use urls that are relative to the SilverStripe directory, since SilverStripe uses the <base href=""> attribute for all pages.
So something like <img src="/themes/yourtheme/subfolder/image.png" /> should work.

Avatar
yurigoul

Community Member, 203 Posts

4 November 2009 at 3:04am

or $ThemeDir/subfolder/yourimage.jpg

Avatar
thepurpleblob

Community Member, 28 Posts

4 November 2009 at 5:28am

Ahh cool.... $ThemeDir... right there in the tutorial page (now I know what to look for) but not, unfortunately, in the Page Controls documentation where I was looking.

Great. Thanks :-)