Note: depending on the document type (invoice, file summary...), the code may be different to produce the same result, because the exported data may be in a different XML tree structure.
Below, text colors are use to identify more easily the document type.
{#if($document.invoice.files.get(0) && $document.invoice.files.get(0).comments)}{#foreach($fileComment in $document.invoice.files.get(0).comments)}{#foreach($commentLine in $fileComment.commentLines)}{$commentLine}{#end}{#end}{#end}{#if($document.invoice.files.get(0) && $document.invoice.files.get(0).comments)}{#foreach($fileComment in $document.invoice.files.get(0).comments)}{#if($fileComment.type=="CONTACT") #foreach($commentLine in $fileComment.commentLines)}{$commentLine}{#end #end #end #end}{#if($document.file && $document.file.comments)
}{#foreach($fileComment in $document.file.comments)}
{#foreach($commentLine in $fileComment.commentLines)}
{$commentLine}
{#end}
{#end}{
#end}{#if($document.file && $document.file.comments)}{#foreach($fileComment in $document.file.comments)}{#if($fileComment.type=="COMMENT")#foreach($commentLine in $fileComment.commentLines)}
{$commentLine}{#end}{#end #end #end}
{#if($document.file && $document.file.comments)}{#foreach($fileComment in $document.file.comments)}{#if($fileComment.type=="CONTACT")#foreach($commentLine in $fileComment.commentLines)}
{$commentLine}{#end}{#end #end #end}
{#if($document.file && $document.file.internalComments)}{#foreach($fileComment in $document.file.internalComments)}{#foreach($commentLine in $fileComment.commentLines)}{$commentLine}{#end}{#end}{#end}