Customizing the filefield format in views

Often times, you may want to customize the appearance of a views field, or perhaps add a bit of logic to the output. You can customize the display of any field in Views by utilizing the Views Customfield module.

Here's an example of how to breakdown a basic cck fieldfield into its constituent parts.

<?php //print var_export($data, TRUE); //prints out all available fields in view $value = $data->node_data_field_document_field_document_fid; //relevant fid if ($value != NULL){ $file = field_file_load($value); //print_r($file); //prints out various rows for file array $filepath = base_path().$file['filepath']; $filename = $file['filename']; $icon = theme('filefield_icon', $file); $filesize = format_size($file['filesize']); $link = "$filename"; //print "
".$icon." ".$link." ".$filesize."
"; print $icon; } ?>

For filefields with multiple values, you can use this model:

<?php //print var_export($data, TRUE); //used to find all available variables in views $data array foreach ($data->node_data_field_rfp_exhibits_field_rfp_exhibits_fid as $key => $value){ if ($value['fid'] != NULL){ //print_r($file); //used to find all available variables in filefield array $file = field_file_load($value['fid']); $filepath = base_path().$file['filepath']; $filename = $file['filename']; $icon = theme('filefield_icon', $file); $filesize = format_size($file['filesize']); $link = "$filename"; echo "
".$icon." ".$link." ".$filesize."
"; } } ?>

Don't forget to use var_export() in order to find the correct name of your filefield variable. Then replace "$data->node_data_field_document_field_document_fid" with your variable.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.