This version is out of date, covering development from v9.0.0 to v9.3.0. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

^if( condition )^


Code Type: 

Code Scope of Action: 

Code First Added: 

Code Altered: 

 Conditional Mark-up   [other codes of this type]

 n/a   [codes with similar scope]

 Baseline

 format"


^if( condition )^

^if( condition )^ ^endIf^

^if( condition )^ ^else^ ^endIf^

Test the condition, resolving to a true or false result:

Though an ^endIf^ closing marker is not mandatory, users—especially if new to export code—are advised to add one as it gives more clarity as to the end of the output of a true match to condition. If the else/endIf mark-up is omitted the text following the closing )^ of the if tag of the condition is returned up to the end of the current line/paragraph (i.e. up to the next line break in the template source code).

Unlike in very early versions of the app (and thus old examples, the condition statement is a query written in action code (essentially the same syntax as if writing an if() action test. For example,

^if($Name.contains("tbx"))^Matched 'tbx' string.^endIf^ 

…is true if the note's title contains the string "tbx", and exports the string "Matched 'tbx' string.". For a reversed test:

^if(!$Name.contains("tbx"))^No matched 'tbx' string.^endIf^ 

…is true if the note's title does not contain the string "tbx", and exports the string "No matched 'tbx' string.". For a numerical test:

^if($Width>5)^The $Width is greater than 5.^endIf^ 

…is true if the note's width exceeds 5.0 and exports out the string "The $Width is greater than 5."

For the first two examples above the value matched can be an actual string or a regular expression.

Using an ^else^ logic branch, different information can be exported for true and for false condition matches. Thus:

^if($Width>5)^The $Width is greater than 5.^else^The $Width is 5.0 or less.^endIf^ 

…which, depending on the outcome exports out either the string "The $Width is greater than 5." or the string "The $Width is 5.0 or less."

In the ^if^ condition, the condition query is always evaluated in the context of this note.

Note there is no extended branching form, such as an 'else if' method. For that, nest further ^if()^ tests in the negative result branch (i.e. after the ^else^).