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 Documents:
| 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 |
| {if $size != "M"} | If $size does not equal "M" |
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}
Checkboxes
For a walkthrough on how to accomplish checkboxes, check out this article .
Create PowerPoint Presentations & Show/Hide Slides with Logic
For a walkthrough on how to accomplish this, check out this article.