Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

You do this as any other field:

print render($content['FIELD_NAME']);

In your content type's manage display page set the file field to "table of files"

   <?php 
       $file_uri=$node->my_field['und']['0']['uri'];   
       $file_path = file_create_url($file_uri);
       print "<a href='".$file_path."'>here</a>";
   ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top