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.

{/if}

 

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

  • {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 a M or the $price is greater than 20

 

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}

{$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}

 

Have more questions? Submit a request

15 Comments

  • Avatar
    Darius Grimes

    Would this have to be inserted into the HTML code or is there a method of  inserting it  in a field conditional statement within the document builder?

  • Avatar
    Jeremy Clarke

    Hi Darius,

    You can add (type) it directly into the document builder.  You can also use the html view if you need more advanced formatting to go along with it.

    Thanks!

  • Avatar
    Darius Grimes

    okay what is the secret to getting tables to display correctly, they just jumble up all on the left side of the document and loose formatting from the document builder

  • Avatar
    Jeremy Clarke

    Hi Darius,

    Please submit a support request for your specific issue.

    Thanks!

  • Avatar
    Nur Husnidha Hussain

    When you mentioned Smarty, is it mean all syntax in Smarty can be applied in WebMerge?

  • Avatar
    Jeremy Clarke

    Yes, "most" of the Smarty syntax can be applied. We block a few functions for security reasons.

  • Avatar
    Alliance Theatre Staff

    How do I create an "if" statement for a check box field? ie It has several choices, but I only want to return the value if a specific one is chosen. Equal doesn't work, because multiple values could be chosen.

  • Avatar
    Jeremy Clarke

    @Alliance - that depends on how the checkbox data is being sent over to WebMerge. If it is an array, then you can use {if in_array('Red', $FavoriteColor)}, but if it is a comma separated list, then you can search for the string like: {if strstr($FavoriteColor, 'Red')}

    Please submit a support ticket for more specific assistance :)

  • Avatar
    Han Zuyderwijk

    Will conditional sections work with the Word Docx Documents?

  • Avatar
    Jeremy Clarke

    Hi Han,

    Yes, you can use the if statements in Word templates as well :)

  • Avatar
    Maciej Ratajczak

    Hi Jeremy, could you please tell me how to get rid of line breaks? I have an list in Word document and I don't want to have white spaces. Zapier makes a list for me in the document using Webmerge but if some elements are missing there are white spaces between list elements. I need one element right underneath another.

  • Avatar
    Jeremy Clarke

    Hi Maciej,

    You'll need to start/end the if statements on the same line so that the new line characters are on the inside of the if statements. Like this:

    {if !empty($Name)}
    Name: {$Name}{/if}{if !empty($Phone)}
    Phone: {$Phone}{/if}{if !empty($Address)}
    Address: {$Address}{/if}

  • Avatar
    Maciej Ratajczak

    Wow! that was easy! :) Thanks man!

  • Avatar
    Chameleon Support

    Hi Jeremy,

    how are the if statements handled with in excel?
    basically i have a sumary page (worksheet 1) in excel that i need to template from another worksheet (worksheet 2)
    In my head its quite complex
    i have in this worksheet 2, a total of 51 rows( row 4 to row 54), with 58 columns (H to BM)

    Do i need to format each row on the worksheet 1? i didnt want 45 empty rows visible if only 5 contain data.

  • Avatar
    Jeremy Clarke

    Hello,

    Unfortunately, there isn't a way to "hide" rows in excel if the data is empty :(

    Could you use a Word document instead with a table? You could then hide the empty rows in the table. Please create a ticket for more specific help.

    Thanks!

Please sign in to leave a comment.
Powered by Zendesk