Jump to:

22970 Posts in 11572 Topics by 2823 members

General Questions

SilverStripe Forums » General Questions » Newbie - images?

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: 1198 Views
  • staple
    Avatar
    Community Member
    7 Posts

    Newbie - images? Link to this post

    Hiya,

    I want to add an image to my page.ss - 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?

    Thanks

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Newbie - images? Link to this post

    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:

    $Image.SetWidth(100)

    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

  • staple
    Avatar
    Community Member
    7 Posts

    Re: Newbie - images? Link to this post

    Um...hmm..

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Newbie - images? Link to this post

    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.

  • JennieViv
    Avatar
    Community Member
    1 Post

    Re: Newbie - images? Link to this post

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

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