Conditional code in preprocess_page function? I need to add a conditional code in a my_theme_preprocess_page function.

The conditional should be like: 

if the loaded node has a field called background_image and the value for this field is not empty, then is true
I think this will work for you. Note:


It doesn't check the node type.
It adds the variable has_background_image on any page that has $vars['node'] available in hook_preprocess_page, and only on those pages.
$has_background_image will be true if the field isn't empty (that's the only check).


.

function MYMODULE_preprocess_page(&amp;$vars) {

  $field_name = 'field_background_image';

  if (!empty($vars['node'])) {

    $node = $vars['node'];
    $items = field_get_items('node', $node, $field_name);

    $vars['has_background_image'] = $items ? TRUE : FALSE;
  }
}