Login | Forgot password | Register

X

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.

Jump to:

17480 Posts in 4474 Topics by 1973 members

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 377 Views
  • Fredrik
    avatar
    Community Member
    1 posts

    Check if image exists in template Link to this post

    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 %>

  • grilldan
    avatar
    Community Member
    132 posts

    Re: Check if image exists in template Link to this post

    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"

  • willr
    avatar
    Moderator
    1823 posts

    Re: Check if image exists in template Link to this post

    <% if BannerImage %>
    Render html specific if bannerimage exists
    <% else %>
    Render html for no image
    <% end if %>

    Should work fine!

    377 Views
Page: 1
Go to Top

Currently Online: entercow

Welcome to our latest member: marcusl

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.