antonmihaylov / OpenXmlTemplates

Word .docx templating system that is designer (no scripting tags) and server-friendly (no word installation required)
GNU Lesser General Public License v3.0
92 stars 25 forks source link

Nested repeaters #4

Closed itsamaik closed 4 years ago

itsamaik commented 4 years ago

First of all, great library! Thank you for your work.

I am running into an issue where I am nesting a repeater in another repeater. I thought I could use repeating_repeatingitem_anotherList, however due to ValidateAndExtractTag 'repeatingitem' is being seen as the variable name instead of 'anotherList' (within repeatingitem).

Maybe we can add an InnerRepeatingRepeaterControlReplacer here?

antonmihaylov commented 4 years ago

Yes, the library had problems with nested controls. I went ahead and re-organized it in a way that makes it easier. The style of adding repeatingItem, repeatingConditional, etc.. was too cumbersome to maintain, because it requires a new repeatingX and a InnerRepeatingY for each new case.

As much as I hate it, that meant that I had to change the API completely, because it would become inefficient otherwise.

Now after commit 0d0027cdef436b13f7e6044017f3f3ae4f5fdbd5 (and v.2.0.0 of the nuget package) it can handle any type of nested controls. Including variables inside variables, repeating inside repeating, variables inside repeating, conditionals inside other types and other combinations you can imagine. That would mean that instead of using repeatingItem, you would just use variable as normally.

Only the scope for the variable would now be the current list item. Same is with variable (or anything) inside another variable - the scope for inner content controls' variables would be the outer content control variable (if it's a complex item, as a dictionary).

You can see it in action in the EngineTests directory.