How can I set-up a custom formatter that uses target="_blank"? I've installed the Custom Formatters module, as I could not figure out why my View setting was not working for "Rewrite output" -> "Target" -> "_blank"

I need to recreate either the "Generic File" format or the "Rendered File" -> "Link" format.

This is what I've tried but I suppose 'attributes' is not something I can add for the $variables array in theme() -

$output = '';
foreach ($variables['#items'] as $item) {
  $output .= theme('file_link', array(
    'file' =&gt; (object) $item,
    'attrs' =&gt; '_blank',
    ));
}
return $output;


That formatter code above was found on the CustomFormatters.com site for Generic Image
OK, found an answer that works for implementing the hook_file_link() function in the theme's template.php file:

Answer at https://drupal.org/node/301234#comment-4764468 - copied here:

function THEMENAME_file_link($variables) {
  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

  $url = file_create_url($file-&gt;uri);
  $icon = theme('file_icon', array('file' =&gt; $file, 'icon_directory' =&gt; $icon_directory));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $options = array(
    'attributes' =&gt; array(
      'type' =&gt; $file-&gt;filemime . '; length=' . $file-&gt;filesize,
    ),
  );

  // Use the description as the link text if available.
  if (empty($file-&gt;description)) {
    $link_text = $file-&gt;filename;
  }
  else {
    $link_text = $file-&gt;description;
    $options['attributes']['title'] = check_plain($file-&gt;filename);
  }

  //open files of particular mime types in new window
  $new_window_mimetypes = array('application/pdf','text/plain');
  if (in_array($file-&gt;filemime, $new_window_mimetypes)) {
    $options['attributes']['target'] = '_blank';
  }

  return '&lt;span class="file"&gt;' . $icon . ' ' . l($link_text, $url, $options) . '&lt;/span&gt;';
}


Simply change THEMENAME to your theme name and place the code in the template file. I suppose I could extract this out into a custom formatter too.