I am working on a word automation usingjinja2 templating engine with docxtpl. I wanted the enumeration to start with every time I create a new list in my document. I am not sure how to achieve that.
Code:
from docxtpl import DocxTemplate
import jinja2
_list = [{"name":"John Doe",'books':["first book","second book","third book"]},
{"name":"Jane Smith",'books':["Jane first book","Jane's second book","Janes third book"]}]
doc = DocxTemplate("JinjaTemplates/listBooks.docx")
doc.render({"data":_list})
doc.save(f'test.docx')
In the Template1.docx:
{% for item in data %}
Books owned by {{ item.name }}
{% for book in item[‘books’] %}
1. {{ book }} {% endfor %}
{% endfor %}
Right now, I get it like the following:
Books owned by John Doe
- first book
- second book
- third book
Books owned by Jane Smith
- Jane first book
- Jane's second book
- Janes third book
But the expected one is:
Books owned by John Doe
- first book
- second book
- third book
Books owned by Jane Smith
- Jane first book
- Jane's second book
- Janes third book