Drupal if else pull image field url from page conent

<?php if (! isset($node)){?> <?php } else{ ?> <div class="hero-banner-img" style="background-image: url('<?php print render (file_create_url($node->field_name ['und'][0]['uri'])); ?>')" ></div> <?php }?>
You have to do ! isset node so Drupal knows what field name is associated with the content you are pulling from. Or else you get an error from pages that don't have the field_name.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.