Skip to main content
Participant
August 13, 2022
Question

Whitespace is condition is false

  • August 13, 2022
  • 2 replies
  • 237 views

Hello,

When using the Document Generation API with a condition, a blank line shows up when the condition is false. It works fine when the condition is true.

 

This is for a conditional to only render addressLine2 if the customer has it.

 

JSON:

{
    "addressLine1": "120 Main Street",
    "addressCity": "Horsham",
    "addressState": "OH",
    "addressZip": "11111"
}

 

Word Template:

 {{addressLine1}} 
 {% conditional-section addressLine2 %}{{addressLine2}}{% end-section %} 
 {{addressCity}}, {{addressState}} {{addressZipcode}} 

 

Output:

 

Please let me know if there is a way to resolve this.

 

This topic has been closed for replies.

2 replies

Joel Geraci
Community Expert
Community Expert
August 16, 2022

Glad you found a solution but for future reference if you only want addressLine2 to appear when that property exists and has a value in the JSON, use the line below. 

 

{% conditional-section ($exists(addressLine2) = true) %}{{addressLine2}}{% end-section %}

Participant
August 13, 2022

Ok - So I figured an easy "hack". Instead of using the conditional, you can append the addressLine2 if it exists using <br>