Skip to content

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

Open

Description

@mehdiammar

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

Activity

  1. mehdiammar commented on Nov 18, 2024

    @mehdiammar
    Author

    For those facing the same issue, try:

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

  2. mehdiammar commented on Nov 19, 2024

    @mehdiammar
    Author

    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.

  3. cvas22 commented on Nov 22, 2026

    @cvas22

    @mehdiammar fyi, Docform (the maintained fork at https://github.com/cvas22/docform, docform on PyPI) now documents that subdocs in a loop need {{p item }} alone in their paragraph inside a {%p for %} block, which removes the blank lines. That's in cvas22/docform#180.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions