open-xml-templating/docxtemplater

paragraphLoop doesn't seem to work

OmerWow opened this issue · 2 comments

Environment

  • Version of docxtemplater : latest 3.45.0 (tried it on 3.44 as well)
  • Used docxtemplater-modules : none
  • Runner : Node.JS (latest 21)

How to reproduce my problem :

My template is the following :

image

as you can see it's in hebrew but i don't think that's the problem becuase im getting new lines for each of these conditions, and i though paragraphLoop should not add new lines if a condition is false.

it is in fact written from right to left in the picture because hebrew is RTL but again i don't think that's the problem cause all of the conditions and variables are working perfectly, just the gaps aren't.

this is the output of sections 2 and 3:

image

this happens on many other sections in the file, and sometimes the gaps are even larger, if there are enough false conditions in between.

With the following js file :

image

it's important to note that i've tried all combinations of paragraphLoop and linebreaks: both true, both false, and one of each.
i don't think ive seen eny difference with any of the combinations.

I would expect it to :

not have new lines for each false conditions, like it says in the paragraphLoop docs

Hello,

The rule is the following :

If the opening loop ({#users}) and the closing loop ({/users}) are both on separate paragraphs (and there is no other content on those paragraphs), treat the loop as a paragraph loop (eg create one new paragraph for each loop) where you remove the first and last paragraphs (the ones containing the loop open and loop close tags).

So in your case you have to write :

{#uploadedScreenshot}
...
{/}

There also is a paid module, https://docxtemplater.com/modules/paragraph-placeholder/, which allows you to write the same thing but with just one tag, like this :

{?uploadedScreenshot}Lorem ipsum dolor sit amet

It does not require a close tag and it will automatically remove the paragraph if the content does not match.