Conditional Sections (if / else)

Scenario: You are creating a contract for services that will be rendered by your business. In this document you have the general outlines of your services, along with some specific services you will be providing. However, not all contracts are the same. You have a section in the contract for each of your 5 different services you provide and you only want to show the applicable sections.

No problem! You can use conditional sections to only show the selected service sections. Using the built-in "if" statement blocks, you can determine which sections should be displayed based on the data values of the document.

For example:

{if $State == "CA"}

This section will display if the value for "State" is equal to "CA". The document will continue to display any text in between the "if" block.

{elseif $State == "AZ"}

This section will display if the value for "State" is equal to "AZ".

{else}

This section will display if the value for "State" is anything else.

{/if}

 

Here are a few other example "if" statements you can use in WebMerge:

Example Description
{if empty($address)} If $address is empty (does not have a value)
{if !empty($name)} If $name is not empty (has a value)
{if $price > 100 and $shipping > 10} If $price is greater than 100 and $shipping is greater than 10
{if $description != ''} If $description is not a blank string
{if $size == 'M' or $price > 20} If $size is "M" or the $price is greater than 20
{if $price > 10 and ($size == "M" or $size == "L")} If $price is greater than 10 and size is "M" or "L"
{if stristr($Title, "Fun")} If $Title contains (search for) "Fun"
{if is_array($Colors)} If $Colors is an array/list
{if in_array("Green", $Colors)} If $Colors contains (search array/list) "Green"
{if strtotime($ExpirationDate) > strtotime("2017-12-31")} If $ExpirationDate is after 2017-12-31

 

For more information on using "if" statements, please take a look at the Smarty documentation here: http://www.smarty.net/docs/en/language.function.if.tpl

 

Hide Empty Lines

If you'd like to hide lines that do not have a value, you can use an if statement that keeps the line break inside the if statement.  Like this:

{$InformalGreeting} {$LastName}{if !empty($Company)}

{$Company}{/if}

{$BillingStreet}{if !empty($BillingStreet2)}

{$BillingStreet2}{/if}

{$City}, {$State} {$Zip}

 

Hide Table Rows

If you would like to hide rows in a table, you can use our {tableif} tag which looks just like any other {if} statement.  Like this:

Name Quantity Price Total
{tableif !empty($Product1)}{$Product1} {$Quantity1} {$Price1} {$Total1}{/tableif}
{tableif !empty($Product2)}{$Product2} {$Quantity2} {$Price2} {$Total2}{/tableif}
{tableif !empty($Product3)}{$Product3} {$Quantity3} {$Price3} {$Total3}{/tableif}

 

Hide List Items

If you would like to hide an item in a list, you can use our {listif} tag which looks just like any other {if} statement.  Like this:

  • {listif !empty($Product1)}Product 1: {$Product1}{/listif}
  • {listif !empty($Product2)}Product 2: {$Product2}{/listif}
Have more questions? Submit a request

75 Comments

  • Avatar
    Jeremy Clarke

    Hi Darius,

    Yes, you can do that :)

  • Avatar
    Darius Grimes

    I'm building tables with if statements which work very nicely but is there a way to keep the table rows from breaking across pages?

  • Avatar
    Jeremy Clarke

    HI Darius,

    If you use a Word template, then you can use the functionality that exists in the Table Properties (under Row).

    If you're using the document builder, you can add CSS to your table rows like this:

    <tr style="page-break-inside:avoid">
      <td>Test</td>
    </tr>

    Edited by Jeremy Clarke
  • Avatar
    Darius Grimes

    Hmm that did not work

  • Avatar
    Darius Grimes

    Jeremy,

    I did find and interesting work around. I was using a 2x2 row/column table and the issue was the 1st and 2nd rows were breaking over pages separating my captions in row 1 from the photos below in row 2. I added a 3rd column to the left but merged the 1st and 2nd rows to make a single row column the height of the table. Now it cant break the rows apart on pages because its treats the table as a single row. Works like a charm and stupidly simple.

  • Avatar
    Dee Huss

    Can you have nested if statements?

  • Avatar
    Jeremy Clarke

    Hi Dee,

    Yes, you can! Like this:

    {if $FavoriteColor == "Blue}
    {if $Gender == "Female"}
    TEXT HERE
    {else}
    OTHER TEXT HERE
    {/if}
    {/if}

  • Avatar
    Service Fplus

    Hi Jeremy,

    {
    "status" : "{if $OFFICER_NAME != 'JOHN'}created{else}sent{/if}",
    "sender": "{if $OFFICER_NAME != 'JOHN'}{$OFFICER_EMAIL}{else}abc@gmail.com{/if}",
    "signer1": {
    "embeddedRecipientStartURL": "SIGN_AT_DOCUSIGN",
    "clientUserId": "{$SF_PERSON_ID}",
    "recipientId": "{$LOS_PERSON_ID}"
    }{if !empty($CO_APP_LOS_PERSON_ID)},
    "signer2": {
    "embeddedRecipientStartURL": "SIGN_AT_DOCUSIGN",
    "clientUserId": "{$CO_APP_SF_PERSON_ID}",
    "recipientId": "{$CO_APP_LOS_PERSON_ID}"
    }{/if}
    }

    I've added this code in Customize extra options/settings for delivery. Because of adding {if !empty($CO_APP_LOS_PERSON_ID)} I am receiving the status as "sent" even if OFFICER_NAME is not John. I am receiving "created" status only if I remove {if !empty($CO_APP_LOS_PERSON_ID)}. Can you explain me why?

  • Avatar
    Jeremy Clarke

    Hello,

    The "!=" is a case-sensitive comparison, so this will only return true when the value is "JOHN" and not "John". I suggest something like this instead:

    {if strtoupper($OFFICER_NAME) != 'JOHN'}created{else}sent{/if}

  • Avatar
    Service Fplus

    Jeremy,
    Sorry for the typo. I haven't used either JOHN or John as OFFICER_NAME. So expecting to see "created" status but I am seeing "sent" status instead of "created". I can see "created" status only if I remove this {if !empty($CO_APP_LOS_PERSON_ID)} condition in the above code. Can you help me why {if !empty($CO_APP_LOS_PERSON_ID)} is changing the result of this {if $OFFICER_NAME != 'JOHN'}created{else}sent{/if} block?

  • Avatar
    Jeremy Clarke

    Ahh, I see the issue. We don't allow you to use the if statements outside of JSON fields. We try to parse the JSON first, then we process the merge fields. So your if statement around signer2 is causing invalid JSON so it's not processing any of the settings.

    Can you remove that if statement so that it is valid JSON?

  • Avatar
    Service Fplus

    Jeremy,
    We have configured applicant as signee1 and co-applicant as signee2 and OFFICER_EMAIL as CC. If I remove {if !empty($CO_APP_LOS_PERSON_ID)} like you suggested, I am getting the following error when co-applicant is not present AND CC in the configuration. If I remove that if statement contract is generating either when both applicant and co-applicant are present OR removing the CC.

    Error: There was an error sending the DocuSign invites: INVALID_RECIPIENT_ID: A recipient ID is missing or invalid. Invalid format for recipientId. Int or Guid expected.

    Can you provide us the solution to generate contract when co-applicant is NOT present with CC configuration in the delivery?

  • Avatar
    Jeremy Clarke

    Hello,

    In that case, I suggest you setup 2 DocuSign deliveries on your document then use logic to determine which to use (under More Options). This will allow you to setup the JSON accordingly (if there is a signer 2 or not)

  • Avatar
    Service Fplus

    Jeremy,

    That will have 2 merges and it'll cost us more. Is there any alternative for this problem?

  • Avatar
    Jeremy Clarke

    No, it will not be 2 merges. The logic you setup on the deliveries will only cause 1 of them to be triggered each time.

Please sign in to leave a comment.
Powered by Zendesk