diff --git a/templates/other/accounts.csv.tt2 b/templates/other/accounts.csv.tt2
index ec26aace3c92cad1e776951a51a6fd54dcec43df..531f2a68652a0eb2aa5d2e9c283f776704414408 100644
--- a/templates/other/accounts.csv.tt2
+++ b/templates/other/accounts.csv.tt2
@@ -1,17 +1,22 @@
-[% all_attributes = {} %]
+[%
+    attributes_all = {}
+    attributes_for = {}
+%]
 [% FOREACH account IN accounts %]
+    [% id = account.id() %]
     [% template = account.profile() _ '.tt2' %]
     [% PROCESS $template scope=account.scope() id=account.id() | trim %]
-    [% all_attributes.import(attributes) %]
+    [% attributes_all.import(attributes) %]
+    [% attributes_for.$id = attributes %]
 [% END %]
-[% attributes_list = all_attributes.keys.sort -%]
+[% attributes_list = attributes_all.keys.sort -%]
 username,password,profile,[% attributes_list.join(',') %]
 [%+ FOREACH account IN accounts %]
-    [% template = account.profile() _ '.tt2' %]
-    [% PROCESS $template scope=account.scope() id=account.id() | trim %]
+    [% id = account.id() %]
     [% account.internal_uid() %],
     [% account.password() %],
     [% account.profile() %],
+    [% attributes = attributes_for.$id %]
     [% FOREACH attribute IN attributes_list %]
         [% attributes.$attribute.join(', ').quote('"') %],
     [% END %]