item_has_files()
checks whether an item has any files associated with it. Returns true or false.
Usage
<?php if (item_has_files()): ?> <!-- HTML or PHP that only applies to items with files goes here --> <?php endif; ?>
Arguments
- Item
$item
{{#if - null | (optional)}}
- Item to check. By default, the current item is used.
- {{#if: null | Default:
null
}}
Return Value
Boolean
Examples
Branching display based on whether an item has files
This example works on an admin/items/show page. It first checks if there are no files for the item, and prints the appropriate message. If there are files for the item, it starts an unordered list and uses a while loop to add the list items.
<?php if(!item_has_files()):?> <p>There are no files for this item. <?php echo link_to_item('Add some', array(), 'edit'); ?>.</p> <?php else: ?> <ul> <?php while(loop_files_for_item()): ?> <li><?php echo link_to_file_metadata(array('class'=>'show', 'title'=>'View File Metadata')); ?></li> <?php endwhile; ?> </ul> <?php endif;?>