After 3 days stuck on this problem, and naturally, 15min after crying for help here, I believe I found out how to solve it.
It seems all I needed to do was to use
getRawContent()
instead of
getContent()
for the scriplet to 'copy-paste' the code instead of solving it before assembling it in the file...
this seems to bypass all the limitations of the scriplet printing.