@David Metzler
Thank you!! your solution worked but with modification.
This caused an error:
if ($node->$node->field_file[0]['filepath']) print l(t('Download Article'), file_create_url($node->field_file[0]['filepath']));
recoverable fatal error: Object of class stdClass could not be converted to string
but i removed the first $node-> to have this:
if ($node->field_file[0]['filepath']) print l(t('Download Article'), file_create_url($node->field_file[0]['filepath']));
and it worked! thank you, im still learning PHP syntax and didnt know how to do a simple if else statement like this.
@Francisco, the reason i didn't go with standard drupal behavior is because i didn't want the title of the node to be the link text. That is how it was showing up in my configuration when i selected Generic Files. If there is a way to take take the Label and make it a link to the file in the CCK manage fields admin dialog, i would love to learn about it.
thanks so much for everyone's help. andrea
Message: 4 Date: Thu, 4 Jun 2009 09:50:58 -0700 From: andrea burton andrea.burton@gmail.com Subject: [support] Calling a field in a node template - need PHP help To: support@drupal.org Message-ID: D8BC1E3E-464D-4962-AB73-0047F1CFDD72@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
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
Message: 5 Date: Thu, 4 Jun 2009 19:33:36 +0200 From: Francesco entuland@gmail.com Subject: Re: [support] Calling a field in a node template - need PHP help To: support@drupal.org Message-ID: 5803c9860906041033h62604942hd13955cdd3e3137e@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1
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
Message: 6 Date: Thu, 4 Jun 2009 11:42:31 -0700 From: "Metzler, David" metzlerd@evergreen.edu Subject: Re: [support] Calling a field in a node template - need PHP help To: support@drupal.org Message-ID: 52177C930FA90F4D9888B0343FDB79FBA58C0B@birch.evergreen.edu Content-Type: text/plain; charset="us-ascii"
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']));