open-xml-templating/docxtemplater

Nested Array Looping Issues

micahvandeusen opened this issue · 8 comments

Environment

  • Version of docxtemplater : 3.34.3
  • Used docxtemplater-modules : N/A
  • Runner : Browser

How to reproduce my problem :

My template is the following :

{#products}
{#.} – {.} – {/}
{/products}

With the following data :

{
  "products": [
    [1,2,3,4],
    [4,5,6,7]
  ]
}

I would expect it to render :
– 1 – – 2 – – 3 – – 4 –
– 4 – – 5 – – 6 – – 7 –

Instead it returns :
– 1,2,3,4 –
– 4,5,6,7 –

This was encountered when trying to chunk as described here: #328 (comment)

That's extremely strange ...

Can you share your docx template please so that I can reproduce quickly ?

loops.docx
I was able to reproduce it on the demo site as well with this document and the data listed above.

Selection_001

This is the output that I get and is also the output that I would expect.

Oh in the demo server, it returns :

– 1,2,3,4 –
– 4,5,6,7 –

That's strange.

It seems that it is linked to the usage of the "angular-parser", disabling it should make it work for now if you need a hotfix.

However, I have to work on this to make it work correctly even with the angular-parser.

We are using angular parser so an alternative solution would be appreciated. For now I am able to get around it by chunking rows in the JSON data provided but it’s not ideal and requires returning JSON in the format as nested arrays don’t work:
{“data”:[{“row”: []},{“row”: []}]}

Hello @micahvandeusen ,

This should now be working well with the new version that I've just released, version 3.36.0 3.35.2

Hope that works for you !

The version is 3.36.0