Repository navigation
Description
Copied from python-docx-template issue 500, opened by @rgrignon1 on 2023-06-26.
Describe the bug
In a project with multiple layers of subdocuments, when inserting a subdocument containing a numbered list, pushing it a level deeper break the continuation
To Reproduce
Start with a first docx template with a numbered list generated by a loop (using explicit Word numbering list):
{% for item in content %}
1. {{ item }}{% endfor %}
then follow up with a second docx template:
{{ FIRST_TEMPLATE }}
And then a third:
{{ SECOND_TEMPLATE }}
Now, here comes the generation of the templates into new documents:
# source
tpl_1_path = "./path/first_template.docx"
tpl_2_path = "./path/second_template.docx"
tpl_3_path = "./path/third_template.docx"
# destination
file_1_path = "./path/first_file.docx"
file_2_path = "./path/second_file.docx"
file_3_path = "./path/third_file.docx"
tpl_1 = DocxTemplate(tpl_1_path)
tpl_1.render({"content": ["item 1", "item 2"]})
tpl_1.save(file_1_path)
tpl_2 = DocxTemplate(tpl_2_path)
sub_file_1 = tpl_2.new_subdoc(file_1_path)
tpl_2.render({"FIRST_TEMPLATE": sub_file_1})
tpl_2.save(file_2_path)
tpl_3 = DocxTemplate(tpl_3_path)
sub_file_2 = tpl_3.new_subdoc(file_2_path)
tpl_3.render({"SECOND_TEMPLATE": sub_file_2})
tpl_3.save(file_3_path)Expected behavior
With the exception of newline changes, all output files should be visually identical
Current behavior
First and second files show the same, a two element numbered list, but the 3rd file doesn't continue the numbering
Screenshots
Additional context
On my personal project, when going one layer deeper in subdocuments, the next step even erase the numbering property of the list and turn it into a bullet point list instead.
Sadly, I couldn't reproduce this behaviour as easily and my code and templates contains too much confidential informations to show as is and are too intricate to try to strip it down to a minimalist POC

Activity
cvas22 commentedon Nov 22, 2026
@rgrignon1 fixed in #189. Lists numbered through their style split once nested a second time, the first item got a restarted numbering and the rest didn't, so the count broke. They stay one list at every level now. Also worth using
{{p FIRST_TEMPLATE }}rather than{{ }}for subdocs (see #180).