21308 Posts in 5737 Topics by 2603 members
General Questions
SilverStripe Forums » General Questions » [SOLVED] Set Default image if the image fetched is not found
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 227 Views |
-
[SOLVED] Set Default image if the image fetched is not found

21 February 2013 at 10:05pm
Please help. how i can do this on SS template?
<% control Parent.function %>
$blogimage = $Image.URL<% if $image.url == not found % >
$blogimage = "src/Default_img.jpeg"
<%end_if %>
<% end_control %>how to identify if the image is not found? is there a variable that can be use?
Thanks in advance
-
Re: [SOLVED] Set Default image if the image fetched is not found

22 February 2013 at 2:22am Last edited: 22 February 2013 2:23am
Hi Juan.
Are you using SilverStripe V3? If you are use <% loop %> instead of <% control %>.
<% loop Parent.function %>
<% if $Image %>
$Image
<% else %>
<img src="$Themedir/images/your-image.jpg" alt="" />
<% end_if %>
<% end_loop %> -
Re: [SOLVED] Set Default image if the image fetched is not found

22 February 2013 at 4:06am
Hello IOTI
thanks for the reply..
no im using v 2.4
i have try this solution but its still not working.. :|
-
Re: [SOLVED] Set Default image if the image fetched is not found

22 February 2013 at 9:11am
Juan
You may have to share a little more info with me. Is anything being returned?
What is "<% control Parent.function %> " suppose to be/return?
-
Re: [SOLVED] Set Default image if the image fetched is not found

22 February 2013 at 12:56pm
yes.. ofc
it will return the latest blogpost including
$title, $Image, $Link etc.
now my problem is.. image urls is saved in the db but the pictures is no longer exist in the uploads directory and i want to set default image if its not found.. i dont want to use Jquery.
i have try this. but it doesnt work.. any other solution?
<% if $Image %>
$Image
<% else %>
<img src="$Themedir/images/your-image.jpg" alt="" />
<% end_if %> -
Re: [SOLVED] Set Default image if the image fetched is not found

23 February 2013 at 2:28am
Hey Juan
Ah awesome, now I understand a little more
Looking through the Image.php code there is a function called getTag() that checks if the file exists. This is untested code but I believe it should work.
<% if Image.getTag %>
$Image
<% else %>
<img src="$Themedir/images/your-image.jpg" alt="" />
<% end_if %>if that doesn't work try
<% if Image.getTag != NULL %>
$Image
<% else %>
<img src="$Themedir/images/your-image.jpg" alt="" />
<% end_if %> -
Re: [SOLVED] Set Default image if the image fetched is not found

26 February 2013 at 4:06pm
It worked!
thank you OITI!
Highly appreciated!
| 227 Views | ||
|
Page:
1
|
Go to Top |


