drupaldrupal-7drupal-modulesrenderdrupal-render

Render out file drupal


I have a field called 'field_downloads' which is a file field that allows the user to upload up to 10 files. How can I render these out in page.tpl.php?

Below is the output from page.tpl.php:

$x = node_view($node);
dsm($x['#node']->field_downloads);

enter image description here


Solution

  • You can simply write the following code.

    $list_of_paths = array();
    foreach($x['#node']->field_downloads['und'] as $index => $data)
    {
        $file_uri = $data['uri'];
        $file_path = file_create_url($file_uri);
        $list_of_paths[] = l(t("my file direction"), $file_path);
    }
    print theme("item_list", array(
        'items' => $list_of_paths,
        'type' => 'ul',
        'title' => t('List of file paths.'),
    ));
    

    Here's what you need to know about file_create_url()

    Hope this works... Muhammad.