Render out file drupal
-
22-06-2021 - |
문제
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);
해결책
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.
다른 팁
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>";
?>
제휴하지 않습니다 StackOverflow