1

I have a content type that has a file field. I would like the body field to be able to link to the file. E.g. "Our research (PDF download) shows..." with the link becoming the download path for the file.

I can see the challenge: the path may not even exist at the time of creating the content. Is this something the token module can help with?

2
  • So are you trying to detect non-existing links or display the link on your page?
    – Michiel
    Commented Jan 20, 2012 at 12:22
  • Not really. Just that when you add a node it's empty: no files, no content. I suppose I was thinking I could set the URL of a link in the body to something like [field_file:1] and that drupal might switch this for the URL of file 1 in field_file. Commented Jan 20, 2012 at 16:21

2 Answers 2

1

You could add this inside your node-my_content_type.tpl.php file:

if (isset($node->field_my_file[LANGUAGE_NONE])) {
  print str_replace('[field_file:1]', file_create_url($node->field_my_file[LANGUAGE_NONE][0]['uri']), $node->body[LANGUAGE_NONE][0]['value']);
} else {
  print $node->body[LANGUAGE_NONE][0]['value'];
}

If the file exists, it will be printed as a link in place of the placeholder [field_file:1] in your body.

3
  • Thanks, I made a module for a very similar problem, using hook_filter. Had been wondering if there was a built-in way; apparently not! Thanks for your answer. Commented Jan 21, 2012 at 17:18
  • Actually, it would be cool to make a module (does one already exist?!) that dynamically provides tokens related to fields in the current node, replacing them wherever they exist (and thus D7 would not render them again below the body since they've already been rendered). In D7 something like that would be pretty easy. Commented Jan 21, 2012 at 17:37
  • Yeah, I've written that! Erm, will find a place to post it. Commented Jan 22, 2012 at 18:47
1

Not 100% exactly what you're asking for, but it may solve your requirement:

The IMCE module allows you to upload documents (and images) and integrates them in the body text. You don't need a separate file field if all you need is a document integrated into your text via a link.

0

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.