Hi,
I am stuck on this problem.
I have a News content type with a File field called field_file.
I am trying to figure out how to write the code in the node- news.tpl.php to show the field but only if a file has been uploaded and thus filled that field.
Right now, I have this code to pull in the body and the file_field:
print $body; print l(t('Download Article'), file_create_url($node->field_file[0] ['filepath']));
but "Download Article" shows up in the nodes that do not have a file uploaded into that node.
Im thinking all i need is an if-else statement that says:
If field_file exists, then print l(t('Download Article'), file_create_url($node->field_file[0]['filepath'])); else just print $body
but nothing i have tried works.
Can anyone help me?
thanks! andrea
Hi Andrea,
I have a News content type with a File field called field_file.
I am trying to figure out how to write the code in the node- news.tpl.php to show the field but only if a file has been uploaded and thus filled that field.
Why don't you rely on the standard behavior? Put the text "Download Article" as the field label, and let Drupal show or hide them both (label and field) depending on the field content.
If you want finer control, go ahead and use php, but instead of checking if field_file exists, check if item 0 is empty or not. The fact is that item 0 of each field is always present, regardless of it being filled or not.
Just my two cents, hope this helped.
Regards, Francesco
I'm not 100% sure but have you tried this?
if ($node->$node->field_file[0]['filepath']) print l(t('Download Article'), file_create_url($node->field_file[0]['filepath']));
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of andrea burton Sent: Thursday, June 04, 2009 9:51 AM To: support@drupal.org Subject: [support] Calling a field in a node template - need PHP help
Hi,
I am stuck on this problem.
I have a News content type with a File field called field_file.
I am trying to figure out how to write the code in the node- news.tpl.php to show the field but only if a file has been uploaded and thus filled that field.
Right now, I have this code to pull in the body and the file_field:
print $body; print l(t('Download Article'), file_create_url($node->field_file[0] ['filepath']));
but "Download Article" shows up in the nodes that do not have a file uploaded into that node.
Im thinking all i need is an if-else statement that says:
If field_file exists, then print l(t('Download Article'), file_create_url($node->field_file[0]['filepath'])); else just print $body
but nothing i have tried works.
Can anyone help me?
thanks! andrea
-- [ Drupal support list | http://lists.drupal.org/ ]