Files opening in new window/tab


I’m having trouble finding a way to have file links open either in a new window or tab. We’re about to go public on our site, but I think it may cause issues as people might not realise they have to hit the <- back button and just close the image down.

I found an outdated thread here:

but I don’t think the listed function still exists in the current function list. Also, I’m not sure how or where to edit functions. Our website admin Control Panel has loads of .php files, but I can’t tell where the correct function would be.

Any help would be greatly appreciated.



The 2.0+ equivalent of the display_files_for_item function mentioned in that old post is files_for_item.

What you’d need to edit would depend on exactly where you want to change the behavior: assuming it’s the item show page, it would be items/show.php within your theme (copy the same-named file from application/views/scripts/items/show.php if your theme doesn’t have an items/show.php already).

Thanks for the response, that’s really helpful. I’ve found the correct file now, as below.

I thought I needed to either add the code in on a separate line, or change the line in bold below to: <?php echo files_for_item(array('linkAttributes' => array('target' => '_blank'))); ?>

but neither seem to have the desired effect. The file attachments still open in the existing window.

Any thoughts on where I might be going wrong?

Thanks again

**<?php echo files_for_item(array('imageSize' => 'fullsize')); ?>**

If you’ve got the “gallery” turned on in your theme’s settings, it would be the item_image_gallery call you’d need to change instead (and for that function the array key is link instead of linkAttributes).

Brilliant, that has worked perfectly. I entered the amended code in the () that was already present after the item_image_gallery call.

Thanks very much, greatly appreciated


What if we do not have a “gallery” setting to turn on? (I’m using Berlin.)

I want to have clicks on the link to the Fullsize item in /items/show.php appear in a new tab.



The normal, non-gallery call in a theme is files_for_item, it’s what I mentioned in my first reply on this thread. That’s the function call you’d be looking to change in items/show.php.

There’s an example on that documentation page for adding an attribute to the link (look for the key linkAttributes), and it’s just a matter of replacing the example attribute with 'target' => '_blank'


This did not work, though:

<?php echo files_for_item(array('linkAttributes' => array('target' => '_blank'))); ?>

While Berlin doesn’t have a Gallery option, it does have an “Item File Display” option, which basically moves the files call to the top and tells it to use larger images.

This means there are actually two files_for_item calls in the Berlin items/show.php. Perhaps you edited the one that your theme isn’t actually using.

THANKS! Here is what worked:

<?php if ((get_theme_option('Item FileDisplay') == 0) && metadata('item', 'has files')): ?>
  <h3><?php echo __('Files'); ?></h3>
  <div id="item-images">
       <?php echo files_for_item(array('linkAttributes' => array('target' => '_blank'))); ?>
<?php endif; ?>