渲染文件drupal

时间:2012-07-22 14:52:29

标签: drupal drupal-7 drupal-modules render drupal-render

我有一个名为'field_downloads'的字段,这是一个允许用户上传最多10个文件的文件字段。我怎样才能在page.tpl.php中呈现这些?

以下是page.tpl.php的输出:

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

enter image description here

3 个答案:

答案 0 :(得分:1)

您可以像任何其他字段一样执行此操作:

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

在内容类型的管理显示页面中,将文件字段设置为“文件表”

答案 1 :(得分:1)

您只需编写以下代码即可。

$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.'),
));

以下是您需要了解的file_create_url()

希望这有效......穆罕默德。

答案 2 :(得分:0)

   <?php 
       $file_uri=$node->my_field['und']['0']['uri'];   
       $file_path = file_create_url($file_uri);
       print "<a href='".$file_path."'>here</a>";
   ?>