2

I have a content type with filefield "ttf" wich I want to render as Url to the file . with this url to file I want to create an link :

<a href="<?php print render($content["field_ttf"]); ?>">Download</a>

But this output a wrapper around the url

I know that there is a function field_view_field() that do the Job but I'm looking for a better solution

3 Answers 3

2

You can do this with the combination of 2 contrib modules :

4

Look in the core modules/field/theme/ folder, copy the field.tpl.php file to your theme then rename it to whatever the system name for the field is. i.e field--body.tpl.php

Edit the file to remove the surrounding divs and anything else you don't want. All you actually need is the foreach and the render($item);

Don't forget to clear the cache so it will pick up the new file, hope that helps.

1

The proper solution for controlling rendering of a field, is a formatter. You can change the formatter and it's settings under the content types "Display settings". I believe file fields come with a formatter for rendering as direct links.

It looks to me like you are attempting to do this to late in the page cycle, but if you need to hack it together, provide some more context on where you are doing the rendering, and I'll try to be more specific.

1
  • unfortunately the url formatter provide wrappers by default and the link as a text. I'm doing this rendering in a note.tpl.php file
    – sel_space
    May 22, 2012 at 12:18

Your Answer

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

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