Skip to main content

If statement expressions

CleanSlate allows us to use expressions inside r:if and r:if_not tags. Expressions can be used to check:

  • if a value is blank
  • if a value is not blank
  • if a value contains an exact string or variable
    • Note: contains matches exact strings. If you tried matching Bear and bear, these are not the same strings because one of the b's is capitalized.

What can the if statement expression values be?

The expression can evaluate the following:

  • Custom Page Data
  • Custom Site Data
  • Variables

BLANK & NOT(BLANK()) code examples:

The following code examples will all use a custom site data value for their expression.

Check if my_site_data_name is blank:

<r:if expression="{{ BLANK(my_site_data_name) }}">
  <p>This paragraph will show if <code>my_site_data_name</code> does NOT have content</p>

Check if my_site_data_name is not blank:

<r:if_not expression="{{ BLANK(my_site_data_name) }}">
  <p>Will show if there is content in site data: <r:site:data name="my_site_data_name" /></p>

This could also be written inside the expression using r:if instead of r:if_not:

<r:if expression="{{ NOT(BLANK(my_site_data_name)) }}">
  <p>Will show if there is content in site data: <r:site:data name="my_site_data_name" /></p>

Contains code examples:

The following code examples check variables (which can also be custom page/site data) to see if their value contains the value we are looking for.

To test the following expressions, paste these r:set_var tags above your expressions:

<r:set_var name="bearVar" value="Bear" /> <!-- For testing purposes only! -->
<r:set_var name="wolfVar" value="wolf" />
<r:set_var name="myVar2" value="Bear" />

Check if bearVar contains “Bear”:

<r:if expression="{{ contains(bearVar, 'Bear') }}">
  <p>Contains a Bear.</p>

Check if two variables contain the same value:

<r:if expression="{{ contains(bearVar, myVar2) }}">
  <p>Two variables that contain a value of Bear.</p>

Check if bearVar contains Bear OR if wolfVar contains notARealVar:

We can also combine checks with multiple arguments. This one uses the or operator:

<r:if expression="{{ contains(bearVar, 'Bear') or contains(wolfVar, notARealVar) }}">
  <p>Contains a Bear or wolf.</p>

Check if bearVar contains Bear AND wolfVar contains wolf:

And this one uses the and operator:

<r:if expression="{{ contains(bearVar, 'Bear') and contains(wolfVar, 'wolf') }}">
  <p>Contains a Bear <strong>and</strong> wolf.</p>

NOTE: expression="" can also be written as expr="" for those who like to abbreviate.

NOTE 2: BLANK, NOT, and CONTAINS are case insensitive. They can be upper or lowercase.

Last updated on January 23, 2020.

We welcome all questions, feedback and bug reports. If you're having an issue, we usually need the following information:

  • A brief description of the issue
  • A link to the page where you saw the issue
  • Screenshots that illustrate the problem - How do I take a screenshot?

Kindly email for help or use the form on the request help page.