Description
This shortcode lets you compare two pieces of information so that you can make decisions about what to display on the page. [memb_if] and [memb_compare] are two names for the same shortcode.
Shortcode Examples
Test if two values are equal:
[memb_compare value1="foo" test="==" value2="bar"]
Success!
[else_memb_compare]
Failure!
[/memb_compare]
Comparing a contact field:
[memb_if value1="{{contact.Country}}" test="==" value2="United States"]
Success!
[else_memb_if]
Failure!
[/memb_if]
Comparing a contact custom field:
[memb_if value1="{{contact._MyCustomField}}" test="==" value2="MyValue"]
Success!
[else_memb_if]
Failure!
[/memb_if]
Only succeed on certain days:
[memb_if value1="{{date.N}}" test="in" value2="1,2,3"]
Success!
[else_memb_if]
Failure!
[/memb_if]
Conditionally check an HTML radio button (New in 2.44.53):
<input type="radio" name="_MyCustomField" value="1" [memb_if value1="{{contact._MyCustomField}}" test="in" value2="MyValue" output=" checked=checked "] />
Conditionally select an HTML dropdown item (New in 2.44.53):
<option value="Example" [memb_if value1="Example" test="in" value2="{{contact._MyCustomField}}" output=" selected=selected "]>Example</option>
<option value="Example2" [memb_if value1="Example2" test="in" value2="{{contact._MyCustomField}}" output=" selected=selected "]>Example2</option>
<option value="Example3" [memb_if value1="Example3" test="in" value2="{{contact._MyCustomField}}" output=" selected=selected "]>Example3</option>
Shortcode Parameters
value1 | The first value to compare. Supports merge fields like {{contact.FirstName}}. (Required) |
|---|---|
value2 | The second value to compare against. Can be a literal value or a merge field. (Required) |
test | The comparison operator to use. Defaults to = (equality). See the operators table in Additional Information for all options. |
caseinsensitive | Whether to perform case-insensitive text comparisons. Defaults to yes. Set to 0 to disable. |
not | Reverses the result of the comparison. Use not="not" to invert the match. |
output | Value to output if the test is successful, instead of displaying the enclosed content. |
txtfmt | A comma-separated list of text processing functions to apply to the output. |
capture | Captures the shortcode output and routes it to a variable for later use. |
Additional Information
This shortcode defaults to case-insensitive comparisons for text data.
| equal | == | or | EQ |
| greater than | GT | ||
| less than | LT | ||
| greater or equal | GE | ||
| less or equal | LE | ||
| not equal | != | or | NE |
| begins with | ~= | or | BW |
| ends with | =~ | or | EW |
| contains | ~~ | or | CONTAINS |
| in | in | ||
| not in | !in | ||
| between two values | inrange | ||
| not between two values | !inrange |
When using inrange or !inrange, value2 must be the comma-separated minimum and maximum values to test against.
When using in or !in to test multiple values, value2 must be a comma-separated list of values to match against.
Shortcode Attributes
| Conditional | Yes |
|---|---|
| Nestable | Yes |
| Accepts formatting | Yes |
| Capturable | Yes |