Jump to content

Images (or other stuff) with 'if elsif else' logic


BFD Calendar
 Share

Recommended Posts

I'm trying to show an image on a page. There are three possibilities 1. get an image from the page, 2. if there isn't any, get an image from an image_url textfield on the page, 3. and if there isn't any, get a random image from the homepage.

It seems I'm missing something in my 'if elsif else' logic.... Only the image from the page - if there is one - shows up, nothing else.

    if($page->bfd_people_picture) {
        $images = $page->bfd_people_picture->getRandom(2);
        foreach($images as $image) {
        $thumbnail = $image->width(300);
        echo "<div id='images'><img class='photo' src='{$thumbnail->url}'></div>";
        }
    }
    elseif($page->bfd_image_from_url) {
    	$webimage = $page->bfd_image_from_url;
	echo "<div style='max-width:300px'><img src='{$webimage}' align='right' style='width:100%; height:100%' /></div>";
   }
   else {
	$homeimage = $homepage->images->getRandom()->width(300);
    	echo "<div id='images'><img class='photo' src='{$homeimage->url}'></div>";
   }
Link to comment
Share on other sites

Yes it works, and the link was helpful. It was also helpful as I said because it reminded me to look where I probably should have looked in the first place: the image field stuff. But I was too much fixed on the if elsif else stuff because I had that working somewhere else already.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...