Hi fellow Drupalians,

I have searched the module pages but i couldnt find the thing i want.

I have a view with news items. The view is created using the table style and contains several fields. Icluding the Uploaded: Listed field. This field says yes or no behind the item if there is an attachment or not.

Yes and no is oke.. but i'd rather see a paperclip (like outlook and gmail have). The paperclip is recognizable for users to see instantly if there's an attachment or not.

Anyone have seen a module or knows how i could create this?

Thanks in advance!

-Aeroniro

Comments

matt_harrold’s picture

You could use Views Custom Field and a tiny bit of PHP code to produce what you're looking for.

http://drupal.org/project/views_customfield

David.W’s picture

Thanks again matt,

Except I am bad at php :(. I'll give it a try though i dont know where to start.
Maybe you or someone can give me some example code?

matt_harrold’s picture

Views Custom Field exposes an object called $data with the fields you've added to your view.

1. Make sure you add the file upload listed field,
2. tick the checkbox to hide from display,
3. add a custom field, use the PHP option, and paste in the sample code.

You might need to put this bit of code in temporarily to work out the exact name of the variable .. I don't know off the top of my head.

  print_r($data);
  // the two lines need changing to suit your view and paperclip image
  $is_listed=$data->file_upload;
  $paperclip="sites/default/files/path/to/paperclip.png";
  if($is_listed=='Yes'){
    print "<img src='{$paperclip}' />";
  }
David.W’s picture

Matt, ur a hero, thanks alot!
I didn't try it though, i will do later this day/week when i have enough time ;).

But thanks anyway for ur help!

David.W’s picture

this is the outcome:

[upload_list] => 1 (there is an attachment)
and
[upload_list] => (no attachment)

I inserted the code without the if statement and the paperclips are printed, so that works.
But with the if statement it doesnt work. I think its because I dont know which fieldname to use.. :x

i did this for now:

  // the two lines need changing to suit your view and paperclip image
  $is_listed=$file_upload; <-- am i wrong here??
  $paperclip="/sites/default/files/images/paperclip.gif";
  if($is_listed=='Yes'){
    print "<img src='{$paperclip}' />";
  }

Thanks again for helping ;)
I'll tinker with it meanwhile waiting for ur answer

David.W’s picture

Got it!!!
Because i'm a php noob, i tinkerd too much with your precious code! But, i took a few steps back and got the right code now.

Here it is:

  // the two lines need changing to suit your view and paperclip image
  $is_listed=$data->upload_list;
  $paperclip="/sites/default/files/images/paperclip.gif";
  if($is_listed>=1){
    print "<img src='{$paperclip}' />";
  }

Thanks alot matt!