Conditional content tags give you the ability to test for certain conditions (such as whether or not specific fields have data) and then populate content based on the results of the test; usually TRUE or FALSE.


Conditional logic can be stored in both Global Content and Content Collections and specific to PDFs and paragraph blocks.


A typical tag works something like this:


{if (someprofile field)  eq (true)} “Some True Value” {else} “Some False Value” {/if}

For every {if} there must be a closing {/if} tag. However, you may notice there is no closing tag for an {else} tag. {else} tags are simply the instructions to carry out if the test returns FALSE.


You can use these logic tests:


eg

neg

gt

lt

gte

lte

||

| strstr:

Equals

Not Equals

Greater Than

Less Than

Greater Than or Equal

Less Than or Equal

OR

"String" Contains 'String' (no spaces allowed)


You can access any data field in the contacts or user database simply by putting the proper variable in front of the name of the data field. This statement looks for the data field “first_name” in the contacts database ($c.)  The '' simply means the data field is empty.


Note: You will want to comment out the conditional code so that it does not display to users in email templates. Not required for PDFs.




If first_name doesn't exist, use fallback content, otherwise use the first_name.


.

<!--{if $c.first_name eq ''}-->

Dear Valued Customer,

<!--{else}-->

Hello, [first_name]!

<!--{/if}-->




You can combine multiple tests using “and” / “or”. For example, this statement looks to see if the contacts first_name AND last_name are blank: 


.

<!--{if $c.first_name eq '' and $.last_name eq ''}-->

Dear Valued Customer,

<!--{else}-->

Hello, [first_name] [last_name]!

<!--{/if}-->





The following statement tests to see if a profiles ($p.) phone number is defined for a user, and if not, provides a default contact number.


.

If you have any questions, please contact us at: 

<!--{if $p.phone eq ''}-->

1-888-999-9999

<!--{else}-->

[p:phone]

<!--{/if}-->





Also, by using {elseif} you can nest multiple tests together. This statement checks to see if “Product 1” exists, then checks again to see if “Product 2” exists and if neither are true {else} displays “The rest of the products”.


.

<!--{if $c.product eq 'Product1'}-->

This is the first product.

<!--{elseif $c.product eq 'Product2'}-->

This is the second product.

<!--{else}-->

The rest of the products.

<!--{/if}-->





Separately, you can 'call' a specific field, in a specific item that is in a Content Collection. This would allow you to use content collections as a sort of mini-database, which eases the maintenance and input of data by utilizing the ability to download and upload data.


[cc(collection_name):FieldName item="ItemName"]

[cc(product_descriptions):short_description item="Mutual Funds"]

You can then use conditional logic to test what a user has selected from a content collection. Take notice the syntax is slightly different. This would allow you to customize content, colors and even images based up on a user's selection.


.

{if $cc:states.name.cc_item eq 'Texas'}

Texas requires this disclaimer

{elseif $cc:states.name.cc_item eq 'Oklahoma'}

Oklahoma requires a different disclaimer

{else}

Use this disclaimer for all the other states.

{/if}





Yes, you can also use conditional logic to create dynamic CSS. This would allow you to change styling based on a user’s profile or their selection from a content collection. The {literal} tags are required since the variable container is brackets-with-brackets. This example passes the value of a profile field, to a variable used with in the CSS. For example:


.

{assign var=fav_color value='[p:favorite_color]'}

{literal}

<style>

.box_background {

background-color:{/literal}{$fav_color}{literal}

}

</style>

{/literal}




The following syntax allows you to assign any value to a local variable, which can then be used repeatedly throughout an asset to control styling or content. This example puts a colored background box on a PDF that dynamic text could then overlay.


.

{assign var=is_selected value='[cc(favorite_color):active_color]'}

{if $is_selected eq 'Red'}

<div style="background-color:#c03427; width:100%; height:100%;">&nbsp;</div>{/if}





In a similar fashion, you can poll for data from a user’s profile field, assign it to a variable and re-use it throughout the asset, draw boxes with it, pull in related imagery or create dynamic CSS.


.

{assign var=is_selected value='[p:favorite_color]'}

{if $is_selected eq 'Red'}

<div style="background-color:# c03427; width:100%; height:100%;">&nbsp;</div>{/if}