i have checked both templates, i will try to explain why each template does not work as expected.
in both of your templates the table is defined with text wrapping enabled
when this option is enabled it causes the XML of the paragraphs around the table (both the the one at the top and at the bottom) to be affected. what does this mean?
it means that visually the representation of the nodes in the template is like this:
- previous paragraph (visually the one at the top of the table)
- table
- next paragraph (visually the one at the bottom of the table)
however, internally the real representation in the XML is like this:
- previous paragraph (visually the one at the top of the table)
- table
- next paragraph (visually the one at the bottom of the table)
this behavior produces different results on each of your templates
for template v2
the template produces tables overlapping because this is the normal behavior of a table with text wrapping enabled when there is no text around. if you put two tables with text wrapping enabled and there are no paragraphs around them, the tables will overlap.
in this case the loop in the XML is represented like this
- paragraph 1 (start of loop
{{#each}}
) - table
- paragraph 2 (empty one)
- paragraph 3 (end of loop
{{/each}}
)
in our docx processing if we detect paragraphs with no more text other than the handlebars calls, then after processing the template, these paragraphs are removed in order for them to not affect layout, so based on this the final result of the loop is this:
------ iteration 1 -----------
- table
- paragraph 2 (empty one)
------ iteration 2 ----------- - table
- paragraph 2 (empty one)
------ iteration 3 ----------- - table
- paragraph 2 (empty one)
------ ...continues... -----------
this is why the final result is overlapping tables, because for sibling tables (that have text wrapping enabled) to render correctly in MS Word the internal representation should be like this
- table
- empty paragraph
- empty paragraph
- table
- empty paragraph
- empty paragraph
how to fix the template v2?
you have two options:
- you can either disable the text wrapping in the table
- or prevent the paragraph that contains the end of loop to be removed, if you go with this option then you only need to put a leading space in the paragraph that contains the end of loop. so it should look like this
<empty space here>{{/each}}
with either of these solutions you should be able to produce the expected result
for template v2.1
in this case the loop in the XML is represented like this
- table
- paragraph 1 (start of loop
{{#each}}
) - paragraph 2 (empty one)
- paragraph 3 (empty one)
- paragraph 4 (end of loop
{{/each}}
)
as you can see, the problem is clear, the loop does not wrap the table, there is only empty paragraphs in the loop body, so this template does not produce anything meaningful
how to fix the template v2.1?
you have two options:
- you can either disable the text wrapping in the table
- or you can put the start of loop in a paragraph that is not around the table, you can create a new paragraph before the paragraph 1 and there put that start of the loop, just similar to the template v2
i hope this clarifies the reason of the results, we don't plan to do something to change the output when tables with text wrapping is enabled, as described there is easy solution for this just by changing the template. applying a solution that might try to "fix" this automatically will cause side effects on other cases.