I need to print the URL of an image in a content type TPL file. I can do this with the following code:
<?php $file = file_load($node->FIELD_NAME['und']['fid']); ?> <?php print file_create_url($file->uri); ?>
However if the field is empty then I get errors on the screen. I tried only printing the URL if $file had a value:
<?php if (!empty($file)): ?> <?php print file_create_url($file->uri); ?> <?php endif; ?>
However im still getting the errors if the field is empty. I understand that it is the first line of the code which creates the variable that is causing the issue. How can I rewrite this to not cause errors?
By the way im a themer not a back-end developer so if there is a more 'themer friendly' solution that would be my preference.