Login | Forgot password | Register
What is OpenID?
OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.
With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.
For more information visit the official OpenID site.
Archive
SilverStripe Forums » Archive » Check if image exists in template
Our old forums are still available as a read-only archive.
|
Page:
1
|
Go to End | |
| Author | Topic: Check if image exists in template | 443 Views |
-
Check if image exists in template

7 September 2008 at 8:10am
Hi, i'm new to PHP and Silverstripe, but using it to build a site right now and so far i like the flexibility alot. Question:
I have extended my page to include an ImageField (followed the tutorial) and i want to use the image as a banner on the page if there is an image attached. How do i check if an image exists in the template? Sort of like this:<% if BannerImage %>
Render html specific if bannerimage exists
<% else %>
Render html for no image
<% end if %> -
Re: Check if image exists in template

7 September 2008 at 9:40am Last edited: 7 September 2008 9:43am
Hmmm. You could try this:
1) Make a Page called "bannerimage" with the html for the banner.
2) use this in your page.ss file<% if Page(bannerimage) %>
$Content
<% else %>
render html for no img
<% end_if %>This might work, it might not work, I'm not sure.
**edit**
If that doesnt work, try this:<% if Page(bannerimage) %>
<% control Page(bannerimage) %>
$Content
<% end_control %>
<% else %>
render html for no img
<% end_if %>**edit**
Don't forget to go to the behavior tab of the "bannerimage" page, and turn off "show in menus" and "show in searches" -
Re: Check if image exists in template

7 September 2008 at 11:29am
<% if BannerImage %>
Render html specific if bannerimage exists
<% else %>
Render html for no image
<% end if %>Should work fine!
| 443 Views | ||
|
Page:
1
|
Go to Top |
Currently Online: chingochango, Euphemismus, Capt. Morgan, Ryan Marshall, Stuckinrealtime
Welcome to our latest member: nkdweb



