Skip to content

Sub documents in bulleted list results in extra blank lines #129

Closed

Description

@cvas22

Copied from python-docx-template issue 574, opened by @mehdiammar on 2024-11-18.


Describe the bug

If you attempt to render sub documents in a bulleted list using a for loop, an extra bullet point is added for each sub document.

To Reproduce

  1. Create a word document with any text in it, can even be a single word. This will be the sub document.
  2. Create a master template document, add a for loop to render sub docs in a bulleted list:

{% for item in list %}
a) {{ item }}{% endfor %}

  1. Try to render the template with the following code:
tpl = DocxTemplate(PATH_TO_MASTER)
sd = tpl.new_subdoc(PATH_TO_SUB_DOC)

context = {
 "list": [ sd ]
}

tpl.render(context)
tpl.save(OUTPUT_PATH)

Expected behavior

The list of sub docs should be rendered correctly.

Screenshots

1
2


Comments from the original thread

@mehdiammar on 2024-11-18:

For those facing the same issue, try:

{%p for item in list %}
a) {{ item }}{% endfor %}

@mehdiammar on 2024-11-19:

I just noticed this results in my extra bullet points at the bottom of the page, seemingly disconnected from the for loop. If this could be looked at, it would be greatly appreciated.

Activity

  1. added
    bug
    on Nov 9, 2026
  2. cvas22 commented on Nov 22, 2026

    @cvas22
    OwnerAuthor

    @mehdiammar documented in #180: subdocs need {{p item }} alone in their paragraph, inside a {%p for ... %} block in a loop. That's what gets rid of the extra blank lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions