I would like to output the raw filefield filepath value of my uploaded file in my views-view-field--....tpl.php.

When I use $fields['field_video_fid']->content, I get the file path and unwanted html markup:

sites/default/files/videos/bars.flv

How do I get just the file path? Also, why is it using the class 'imagefield-formatter-path' instead of filefield-formatter-path'?

Thanks.

Comments

apersaud’s picture

My unwanted html markup should have looked like this:

<span class="imagefield-formatter-path">sites/default/files/videos/bars.flv</span>
apersaud’s picture

I decided to get the filepath by just removing the html mark up using strip_tags().

dopry’s picture

Status: Active » Closed (fixed)

You can also use the file object... If you're doing custom stuff in your template try a print_r($node) or create a custom formatter...
It's probably available in node->field_name[$delta]['filepath']...

ArtAnna’s picture

You can redefine basic output functions from ...\modules\imagecache\imagefield_formatter.inc.

1. In your case copy following function code to your template.php

function theme_imagefield_formatter_path_plain($element) {
  // Inside a View this function may be called with null data.  In that case,
  // just return.
  if (empty($element['#item'])) {
    return '';
  }

  $field = content_fields($element['#field_name']);
  $item = $element['#item'];
  if (empty($item['fid']) && $field['use_default_image'])  $item = $field['default_image'];
  // If there is no image on the database, use default.
  if (empty($item['filepath']))  $item = array_merge($item, field_file_load($item['fid']));

  $attributes['class'] .= ' imagefield-formatter-path';
  return '<span '. drupal_attributes($attributes) .'>'. file_create_path($item['filepath']) .'</span>';
}

2. Rename function name as:
function yourthemename_imagefield_formatter_path_plain($element)...

3. Delete output in return:
return file_create_path($item['filepath']);

Enjoy the silence =)

akahn’s picture

Sure, there are ways around this, but if I'm asking my view to output a raw file path, shouldn't I get a file path, rather than a much less useful filepath-wrapped-in-span-tags? Dopry, what is the reason for wanting these span tags?

elly’s picture

Just ran into this as well - I'm trying to do some complex views theming and insert the filepath into some other markup, so the extra span tags are really bothersome!