Drupal - Show file field as thumbnail if file is an image?
I could also create a template for the comment, or the field and then insert an "if".
All you need is writing your own display formatter for file fields. have a look at field_example module to see where you should start:
first define your display formatter using hook_field_formatter_info, here with field types
you can specify that this display formatter is for file fields.
then all you need is implementing hook_field_formatter_view, here you should output different $element
based on $item
extension.
after developing this tiny module, go to comment display setting
in your content type page and select your new display formatter to rendering that field.
From field example module:
- field_example_field_formatter_info
- field_example_field_formatter_view