diff --git a/include/class.forms.php b/include/class.forms.php
index 66eb26b5e38cfa9dcd61b3040adaaf3bfc621f98..f0ddc5df0f5799113b0065190a1133c42ae24fa4 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -2184,6 +2184,42 @@ class FileUploadField extends FormField {
             $this->attachments->deleteAll();
         }
     }
+
+    function asVar($value, $id=false) {
+        return new FileFieldAttachments($this->getFiles());
+    }
+    function asVarType() {
+        return 'FileFieldAttachments';
+    }
+}
+
+class FileFieldAttachments {
+    var $files;
+
+    function __construct($files) {
+        $this->files = $files;
+    }
+
+    function __toString() {
+        $files = array();
+        foreach ($this->files as $f) {
+            $files[] = $f->file->name;
+        }
+        return implode(', ', $files);
+    }
+
+    function getVar($tag) {
+        switch ($tag) {
+        case 'files':
+            throw new OOBContent(OOBContent::FILES, $this->files->all());
+        }
+    }
+
+    static function getVarScope() {
+        return array(
+            'files' => __('Attached files'),
+        );
+    }
 }
 
 class InlineFormData extends ArrayObject {
diff --git a/include/class.variable.php b/include/class.variable.php
index a7fc036d1f13ee54be49c89e7ac0d4fd546a26c2..6401007aee906045f70c78f51ead62ef15c34a17 100644
--- a/include/class.variable.php
+++ b/include/class.variable.php
@@ -127,7 +127,7 @@ class VariableReplacer {
             $type = $content->getType();
             $existing = @$this->extras[$type] ?: array();
             $this->extras[$type] = array_merge($existing, $content->getContent());
-            return '';
+            return $content->asVar();
         }
 
         if ($parts[0] && @isset($this->variables[$parts[0]])) { //root override
@@ -321,18 +321,25 @@ class PlaceholderList
 class OOBContent extends Exception {
     var $type;
     var $content;
+    var $text;
 
     const FILES = 'files';
 
-    function __construct($type, $content) {
+    function __construct($type, $content, $asVar='') {
         $this->type = $type;
         $this->content = $content;
+        $this->text = $asVar;
     }
 
     function getType() { return $this->type; }
     function getContent() { return $this->content; }
+    function asVar() { return $this->text; }
 }
 
+/**
+ * Simple wrapper to represent a rendered or partially rendered template
+ * with extra content such as attachments
+ */
 class TextWithExtras {
     var $text = '';
     var $extras;