I have a file field from the File Entity module (2.x-alpha2) attached to a content type. I'm trying to customize the output of this field so that it links to the main node (this is for a teaser display). I'm overriding the node template for the teaser display, so I have access to the renderable field array for the field as well as the node path.

I'm trying to find the best approach for wrapping the image in a link. I can easily create the link tag using the l() function. However, I can't just wrap that around the rendered file field because it renders with a lot of extra markup aside from just the image tag.

What is the best approach to handle this? Programmatically altering the theme functions that render the actual image tag? It's not clear to me if I can do that quite yet.

If it helps at all, I'm also using the Media module (2.x-alpha2).

  • I'm nearly positive I asked this same question a few months ago.
    – mpdonadio
    Commented Oct 14, 2013 at 21:43

2 Answers 2


I would create a custom field formatter for rendering the cck field itself. Look for hook_field_formatter_info, hook_field_formatter_view and implement your own custom module

There is also this module https://drupal.org/project/custom_formatters you might want to check out.

  • You could also override the field template. If you are using HTML5 it is valid to have other markup in an a tag, so even if you end up with some divs in there it's not the end of the world.
    – rooby
    Commented Oct 14, 2013 at 21:36
  • Thanks! This was very helpful in understanding how field view modes work.
    – Brian
    Commented Oct 15, 2013 at 14:48

So, after exploring the option of creating my own field formatter, it seems that it wasn't necessary. I was able to:

  1. Change view style to "Fields" instead of "Content"
  2. Add relationship to File
  3. Add the field "File: Rendered", and select the appropriate display style.

The output of this rendered field does NOT contain any of the extra markup for the field output itself, and I can modify the views row style to not output any of the outer divs that are normally added for fields.

It's important to note that when rendering a views row style as "Fields" instead of "Content", that Views will NOT render the complete file entity like it would for "Content". So, if your file entity has additional fields attached to it, they will not be rendered along with the field when using the method outlined above. See this issue I created regarding this behavior: https://drupal.org/node/2112329

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.