I need to wrap a div in a template file in an a tag whose href comes from a file field. My markup would be something like this:

<a href="/path/to/file">

Sounds easy enough but the uri that I'm given looks like this "public://newsletter/downloads/Issue 95_0.pdf" which renders but when clicked doesn't go anywhere. How can I turn that link into a valid link?

1 Answer 1


I needed to use the drupal function file_create_url and PHP parse_url to accomplish this.

function newsletter_preprocess_node(&$variables) {

  if ($variables['type'] === 'newsletter' && $variables['view_mode']) {
    // Generate a path to the file based on the download uri
    $path = $variables['field_download'][0]['uri'];
    $path = file_create_url($path);
    $path = parse_url($path);
    $path = $path['path'];
    $variables['download_link'] = $path;

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.