Drupal 6 Display File Attachments in Contemplate Templates
In earlier tutorials I showed how to use the Drupal module Contemplate to customize the default output for content types. Recently I developed a SMS Gateway Module for the Esendex service provider and documented it in a tutorial here.
However, I noticed a bug. Despite attaching the module zipped tar file, when the node was displayed on the screen, the links to download the code was not being displayed. I had created a contemplate template for the story content type in my Drupal 6 Node Inside Another Node Using Word-Wrap Panel tutorial. But I had not considered the possibility of attaching files for download. So this needed to be remedied.
Firstly, locate the template file that needs some treatment.
$ cd badzilla/sites/all/contemplatesThe using your favourite editor, edit node-story.tpl.php. We need to add the variable $node->content['files']['#value'] which displays the table and the links for downloading attachments. This should be placed after the code to print the content body.
<div id="thmr_3" class="thmr_call">
<span class="field field-type-text field-field-body">
<span class="field-items">
<span class="field-item">
<?php
if ($node->field_child_nid[0]['value'] and $node->field_child_nid[0]['value'] != $node->nid) {
$child = node_load($node->field_child_nid[0]['value']);
print "<div id='child-right'>";
$output = node_view($child, FALSE, FALSE, FALSE);
print preg_replace('#<span class=\"submitted\".*[0-9]</span>#ms', "", $output);
print "</div>";
}
?>
<?php print $node->content['body']['#value']; ?>
<?php print '<br />' . $node->content['files']['#value']; ?>
</span>
</span>
</span>
</div>Note: This code includes my changes from earlier tutorials
This will result in the code to download attached files to be displayed.
File Attachment