17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1691 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!
| 1691 Views | ||
|
Page:
1
|
Go to Top |



