[support] Calling a field in a node template - need PHP help

Francesco entuland at gmail.com
Thu Jun 4 17:33:36 UTC 2009


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


More information about the support mailing list