fm:If


This component will display its contents if the comparison is true. The default comparison will test if the value is "truthy" based on PHP's truth table. If the comparison evaluates to false this component will only display the contents that are within the fm:else node.

Simple example using the default comparison ("truthy")

In this example "failure" will be displayed if the value is 0, an empty string, or a string of only whitespace characters. Anything else will yield "success".

<fm:If value="{$$get.msg}"> success <fm:Else> failure </fm:Else> </fm:If>

Testing for an integer

This will test the value to see if it's an integer. This may be important when checking if you're working with a number that could be a valid page number or a media item's offset in a list.

<fm:If value="{$$get.offset}" comparison="integer"> Displaying entry {$$get.offset} <fm:Else> Sadly we're currently unable to support fractional media items :( </fm:Else> </fm:If>

Testing for regerx match

This will test to see if the value matches the provided regex

<fm:If value="{$$get.query}" comparison="matches" compareTo="/.*Blue.*/"> We found Blue <fm:Else> Sorry, this does not contain the word Blue </fm:Else> </fm:If>

Comparing two numbers

To test if one value is greater than another you may specify "gt" (greater-than) or "lt" (less-than) as the comparison:

<fm:If value="{$$get.rating}" comparison="gt" compareTo="3"> This got a rating greater than 3! <fm:Else> This got a rating of 3 or lower. </fm:Else> </fm:If>

To test if one value is greater-than / less-than, or equal-to, another you may specify "gte" (greater-than-or-equal-to) or "lte" (less-than-or-equal-to) as the comparison:

<fm:If value="{$$get.rating}" comparison="gte" compareTo="3"> This got a rating greater than or equal to 3! <fm:Else> This got a rating less than 3. </fm:Else> </fm:If>

Supported Attributes

NameRequiredDefaultDescription
compareToOptionalN/AThe variable to compare to, if applicable
comparisonOptionaltruthyThe operation to use to test, one of: "truthy", "=", "gt", "gte", "lt", "lte", "integer","contains","inList","empty\,"notempty","matches"
delimiterOptionalN/ARequired it comparison is of time inList, eg. ca,us,fr,sp. Delimiter would be ','
valueRequiredN/AThe variable to test

See also