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.

General Questions

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

Newbie - images?


5 Posts   1254 Views


13 March 2009 at 2:02pm Community Member, 7 Posts


I want to add an image to my - what is the best syntax to use..

- Should $ImagenameImage print out a html tag for an image, if so what dir should it live in?
- Where should I put images that part of a template but not called from CSS?


Carbon Crayon

13 March 2009 at 2:13pm (Last edited: 13 March 2009 2:13pm), Community Member, 598 Posts

Hi staple

I'm not sure I totally understand you question.

There are a couple of ways to add images in your tempalte, the most common being;

$Image - this will add a complete image HTML like <img src="myImage.jpg" alt="Image name" >

$Image.URL - this will return the URL so that you can use your own tag like so: <img id="img" src="$Image.URL" alt="some proper text" >

you can also resize images in the template:


Unfortunately you cant then add .URL on the end, so if you want to resize and only use a url then you need to do somthing like this:

<% control Image %>
<% control CroppedImage(100,100) %>
<img src="$URL" alt="some text" >
<% end_control %>
<% end_control %>

Hope that helps :)


13 March 2009 at 3:07pm Community Member, 7 Posts


Thanks for the reply.. I guess I mean..

I have an image in '/themes/MyTheme/images/theMoon.jpg' but in order to put it in the template I want the path to work properly (I am rewriting my baseurl). In cakePHP I would have used the image helper...

echo $html->image('title', 'path')

...and it would automatically add the right root url.

Does that make sense? :-)


13 March 2009 at 3:24pm 4085 Posts

If the image is part of your template, you can call it like Aram said, only use the $ThemeDir global var to refer to the current theme directory. If the image is part of the model, however, you can call it using its fieldname.. e.g. $MyImage, which will render an image tag for you. Otherwise, for a custom tag, you can do img src="$MyImage.URL" alt="" etc...

Helpers, despite all their admirable attempts to streamline development, break the MVC pattern and should be avoided when possible.


18 March 2009 at 5:16pm Community Member, 1 Post

Im a newbie too, and I am having the same trouble.. :) Thanks for posting.. So psyched to be here!