IF-ELSE Statements - PDF and Word Documents

With conditional statements, you can set- if some condition is applicable, then do something.  Non-IT users can add conditional sections right inside the Word and PDF templates and this doesn't require programming skills.

Let's take the scenario of a loan agreement. If the number of borrowers = 1, then the loan agreement should show only one borrower's name and a signature section. If the number of borrowers = 2, then the loan agreement should show both the borrower names and respective signature sections. This is where if-else conditions come in handy. Instead of maintaining different templates, you can have a single template with conditional statements. They show/hide data based on the input to produce the right document

Creating conditional statements in EDocGen is very easy. Just add relevant tags in the template

This article details creating a  template with conditional fields.  They determine the pieces of information that should be pulled into your document or information that should be displayed.

Let's examine the below template with two text fields.


Simple conditions:

Let's start with a simple condition. If the name is "Steve", we want to show him a message.

{#Enter_Name == "Steve"}
      We're thrilled to have you here.

Notice that the if condition starts with {# and ends with {/}.   In your JSON/XML/Excel, if the value for the "Enter_Name" field is Steve, then this message would be displayed.

Let's say you want to show the telephone number in your documents - only if it's available. This is the condition for checking Boolean.


Use Boolean checking for hiding blanks and empty lines. Ex: If Address value is available, display that. Else show something else.

Compound conditions

EDocGen supports  AND (&&), OR (||). You can create extremely complex conditional statements using them.

{#Enter_Telephone !="" &&  Enter_Name !=""}
   Do something

Similarly you can also use  parenthesis  (condition1 && condition 2) || condition 3)

{(#Enter_Telephone =="1234" &&  Enter_Name !="") ||(#Enter_Telephone =="4567" &&  Enter_Name =="Steve")}
    Do something

Any conditions that start with {^condition} work similar to Else. This determines if a condition's converse is true.

{^Enter_Name} returns true if no value is present for {Enter_Name}.

Let's use both in an example. Addresses frequently include address2 and address3. We can display that using conditions.



{^Address2 }{^Address3}{City}, {State} {Zip}{/}{/}{#Address2}{Address2}{/}

{^Address3} {#Address2}{City}, {State} {Zip}{/}{/}{#Address3} {Address3}

{City}, {State} {Zip}{/}


For table population, the systems loop over JSON /XML/Excel data to populate the rows. So write your conditions right inside the columns. This way you can show/hide a particular row.

{#Job}{#Company =="Oracle"} {Role}


  {Address} {/}{/Job}

Content Blocks

The population of content blocks using if-else conditions is extremely useful for populating product-specific sub-templates and content.

{#type == "1"}
{#type == "2"}
{#type == "3"}