Jump to content

Image check A or B breaks with crop


Peter Knight
 Share

Recommended Posts

Hi

I have a little script that ouputs a default hero image if an image isn't set on the page.

All works great (see below).

I've realised I want to add an image Crop to one or both of these but when I add a Croppabelmage to the page specific image, I get an error. And I get this error even if no image is set. 

I understand what's happening. It's looking for getCrop even though there's no image in the field.

But how to side-step it or do a proper check in this instance?

 <?php
 // Set var for the Hero / Masthead background image
 
// A - The default image
 $image_default = $pages->get(1034)->Hero_Photo_Default->url; 

// or B - The specific page image
$image_hero = $page->Hero_Photo->url; 
 ?>




       <!-- START: Masthead -->   
          <div class="uk-section-default uk-margin-large-bottom  ">

              
              <?php  
              if (count($image_hero)){

                echo"
              <div 
              class='uk-section uk-section-xlarge pk-section-masthead uk-light uk-background-cover' 
              style='background-image: url({$image_hero})'>


                ";}

              else 
                {echo"
               <div 
              class='uk-section uk-section-xlarge pk-section-masthead uk-light uk-background-cover' 
              style='background-image: url({$image_default})'>
              ";}

              ?>
             
                  <div class="uk-container">
                      <!-- <h1><?=$page->title?></h1> --->
                  </div>

              </div>
          </div>
        <!-- END: Masthead -->

 

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