I post file in my template like print content_format('field_file2',$field_file2[0]);
but when filename is very big it looks not good.

How to change file name to "my link" for example or post first 3 words....?

Comments

jpetso’s picture

You've got two options here:

a) Set the "Description" field in the node form to something other than the file name.
b) If that's no option, set $field_file2[0]['description'] to your desired value before calling content_format().

One of those two should do the job.

jpetso’s picture

Status: Active » Fixed

Marking as fixed.

Btw, if you want to disassemble (cut off) the file name, you can find it in $field_file2[0]['filename'].

jpetso’s picture

And just to clarify, this would look something like (attention, untested)

if (strlen($field_file2[0]['description']) > MY_MAX_LENGTH)) {
  $field_file2[0]['description'] = substr($field_file2[0]['description'], 0, MY_MAX_LENGTH - 3) .'...';
}
print content_format('field_file2',$field_file2[0]);

(Mind that the file name is the default value for the description.)

Anonymous’s picture

Status: Fixed » Closed (fixed)