-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variables in blocks #1390
Comments
Why don't you just loop through the array and set the values? |
Well this way I can have the formatting and text in the template and fill the data in the code. I don't see how this would be possible. Especially with two times the same macro FORENAME and two times LASTNAME.
How would you achieve that with a foreach loop? |
When using
That way it will only replace the first value it finds. So first you use cloneBlock and clone the blocks, and after that run your foreach and only replace the first variable at a time. |
If anybody else is wondering how to do this:
Thanks @rkorebrits! This is way cleaner. |
Perfect, that's pretty much how I use it also (although without the second foreach, but assign one by one). Also prefer it like this without preparing the data as it's cleaner to have conditional logic in the foreach imho. Please close the ticket if resolved :-) |
I found two edge-cases where the solution above does not work (but with my PR):
This only works accidentally if the data is in the correct order (CAT before DOG). Otherwise Cat will be replaced with dogs name since the block context is missing,
Obviously only the first one is being replaced. |
|
In a path syntax the CAT.NAME and DOG.NAME makes sense. Yes, the second is worse and I don't even have a workaround for that. |
This is:
Expected Behavior
Being able to create a block with an array of variables (aka foreach in templating).
In the docx "template":
In the code:
I want to start a discussion about this before I might implement it and send a PR.
The text was updated successfully, but these errors were encountered: