I want to include some javascript only if the node has files attached. I'm assuming I can add a conditional to page.tpl.php to do this? I just can't find documentation on how to reference if a node has a file attachment... Thanks!

Comments

Solipsist@drupal.org’s picture

A node with attachments has references to files on the file system and these references are stored in the node object. Some files may be hidden (not listed) so you need to check for that as well.

Try the following code

<?php
foreach ($node->files as $fid => $file) {
  $fcount = ( $file->list ? ++$fcount : $fcount );
}
if ($fcount):
?>
...
<?php endif; ?>
jack.bishop1’s picture

but that foreach gives me an error: warning: Invalid argument supplied for foreach() in /.../template.php on line 129.