i am having difficulties in shaping an IF statement that will allow me to print the following line if the field is not null. Any pointers in right direction would be very appreciated. I am guessing i prob havent even written this correctly, but it works...in that it allows me to download the file by clicking 'download vcard'.

<a href="../<?php print $node->field_directory_vcard[0]['filepath']; ?>">Download Vcard</a>

Comments

kadimi’s picture

Try this, with a little tweaking it should do what you cant:

<?php 
if(isset($field_directory_vcard)){
  $url = url($field_directory_vcard[0]['filepath'], array('absolute' => TRUE));
  print t('<a href="@url">Download Vcard</a>', array('@url' => $url));
}
?>
calebm12’s picture

Thanks for your help! For some reason, the if(isset was not recognizing the null field, so it was printing for every node.
I ended up running into some code that seems to do the trick though.

    <?php
	if ($node->field_directory_vcard[0]['fid']): ?>
<a href="<?php print $base_path . $node->field_directory_vcard[0]['filepath'] ?>">Download Vcard</a>
<?php endif; ?>
kadimi’s picture

You will probably get PHP notices about undefined indexes in the field is not set but I think it's fine.

calebm12’s picture

where would i see these notices. havent seen anything yet. is my code flawed?