Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Can I set a Default Image for ImageField?

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1836 Views
  • socks
    Avatar
    Community Member
    190 Posts

    Can I set a Default Image for ImageField? Link to this post

    No one has responded yet, so let me elaborate. I have an ArticlePage (radio show) that will have a Title, Image, Audio File, and Description. I have set the CMS up with a new ImageField, but for times that the client doesn't have a photo, I would like to set a default image. Any help would be appreciated.

    Thank You,
    Clint

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Can I set a Default Image for ImageField? Link to this post

    Is this possible? Is there a different approach that anyone can think of?

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Can I set a Default Image for ImageField? Link to this post

    Square1,

    the easiest way to do this would be to check if the image exists in the template, rather than inside the CMS (i dont think its supported). To do display a default image if one isnt provided, you can put this in your template:

    <% if Image %>
    $Image
    <% else %>
    <img src="assets/default-image.jpg" alt="Default Image"/>
    <% end_if %>

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Can I set a Default Image for ImageField? Link to this post

    Just tried your suggestion, it worked!

    thank you!

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