0

I created a custom node template in order to change what fields are generated.

  <?php
        print render($content['field_pdf']);

        ?>

The above php code renders the following html:

<div class="field field-name-field-pdf field-type-file field-label-hidden field-wrapper"><span class="file"><img class="file-icon" alt="" title="application/pdf" src="/modules/file/icons/application-pdf.png"> <a href="/sites/default/files/testmanual.pdf" type="application/pdf; length=1607045">lindamanual.pdf</a></span></div>

The problem is I only want the href to be rendered (not the image and the outer div). How can I do this?

1

In the display settings of your field, you can choose to display the "Rendered Content" (what you actually have) or only the URL of the file ("URL to file"). This should only give you the file URL.

  • I'm at -> Home » Administration » Structure » Content types » MyContentType » Manage fields. But can't seem to find this option – Vincent Feb 26 '14 at 9:29
  • You need to go in -> Home » Administration » Structure » Content types » MyContentType » Manage Display – Matt Feb 26 '14 at 9:38
  • Indeed changed to url only. Yet still <a href="' . render($content['field_pdf']) . '"><img src="/sites/default/files/brochure_download.png"/></a> doesn't work. I'll look into this later – Vincent Feb 26 '14 at 13:48
1

Assuming that you wish to override the default rendered content, you have some options.

One option is to use a field--\[type|name\[--content-type\]|content-type\].tpl.php file to override the theming of the particular field. Depending on the field type, you might want to take a look at the original field.tpl.php file in the field's module core or API documentation.

Another option is to take a glimpse of the field's properties with debug($content['field_pdf']); and use the appropriate code in place of the old render() to printout the field's content, essentially ignoring the field's theming function (which I wouldn't recommend because you have to build several variables yourself, for example the path to the filename).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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