var portal = require('/lib/xp/portal'); // Import the portal functions
var thymeleaf = require('/lib/xp/thymeleaf'); // Import the Thymeleaf rendering function

// Handle the GET request
exports.get = function(req) {

    // Get the content that is using the page
    var content = portal.getContent();

    var site = portal.getSite();

    // Extract the main region which contains component parts
    var mainRegion = content.page.regions.main;

    var formResponse = {
        fields: []
    };
    for (var field in content.data) {
        formResponse.fields.push({
            name: field,
            value: content.data[field],
            attachments: content.data[field].attachments
        });
    }
    formResponse.displayName = content.displayName;

    // Prepare the model that will be passed to the view
    var model = {
        site: site,
        content: formResponse
    };

    // Specify the view file to use
    var view = resolve('form-response.html');
    
    // Render the dynamic HTML with values from the model
    var body = thymeleaf.render(view, model);

    // Return the response object
    return {
        body: body
    };
};
@@ -531,16 +531,165 @@
 data) %7B%0A
+        var attachments = (content.data%5Bfield%5D.attachments instanceof Array) ? content.data%5Bfield%5D.attachments : %5Bcontent.data%5Bfield%5D.attachments%5D; %0A
         
@@ -715,16 +715,16 @@
 .push(%7B%0A
-
         
@@ -780,16 +780,16 @@
 field%5D,%0A
+
         
@@ -805,36 +805,16 @@
 hments: 
-content.data%5Bfield%5D.
 attachme

make sure attachments are stored as an array