Whitespace is condition is false

New Here ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

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:

Shrey24785360nvcl_1-1660365424166.png

 

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

 

TOPICS
Bug , Document Generation API , PDF Services API

Views

40

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

LATEST

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 %}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources