I have a table in docx in which i want the rows to be added to table only if the substring exists in the string. have included the image of my template for table here : template for docx table
enter image description here i have a dataset x with are set of names and and numbers eg: {1:{ name:aryan,number:1},2:{anand,2},3:{aishwarya,3}}. i wish to create a table such that i populate the table rows such that i only get the numbers of names that contain substring "arya".the image contains what i was able to make, but having issue with a complex condition in the %tr tag,please help with this please help implementing this correctly.
required output: |C1 | |--------------| | 1 | | 3 |
i am able to filter the data, but additional rows and spaces are added to the table bacuse of the for and endfor loop please help in removing this.
from docxtpl import DocxTemplate
tpl = DocxTemplate('templates/dynamic_table_tpl.docx')
context = {1:{ name:aryan,number:1},2:{name:anand,number:2},3:{name:aishwarya,number:3}}
tpl.render(context)
tpl.save('output/dynamic_table.docx')
template(as in picture):
|C1 |c2 |c3 |c4. |c5. |
|--------------------------------------------------|
| {%tr for i in x %} {%tr if "arya" in i.name %} |
|--------------------------------------------------|
| {{ i.number}} |
---------------------------------------------------|
|{%tr endif %}{%tr endfor %} |
----------------------------------------------------