
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.
//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 "
";
print $icon;
}
?>
For filefields with multiple values, you can use this model:
//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 "
";
}
}
?>
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.
Customizing the filefield format in views | Grasmash
Very nice write-up. I certainly love this site. Continue the
good work!
A blog page regarding engineering: pc speakers
Add new comment