4W WebMerge Tag Reference


[WM-If: Value Operator Value]
...HTML if condition is true...

[WM-If: Value Operator Value ]
...HTML if condition is true...
...HTML if condition is false...

[WM-If: (Value Operator Value) AND (Value Operator Value)
 OR (Value Operator Value)]

[WM-If: Field: ClientName = David]
 Hey David!

[WM-If: Field: Age <> ""]
This person is [WM-Field: Age] years old.

[WM-If CurrentRecordNumber mod 2]
 <tr><td bgcolor="gray">Gray Cell Color</td></tr>
 <tr><td bgcolor="white">White Cell Color</td></tr>

[WM-If: (Field: Age < 18) OR (Field: Age > 65)]
 You qualify for a discount
 The standard price applies

[WM-If: len(Field: Description) > 200]See link for details.[/WM-If]   

Along with the [WM-Else] and [/WM-If] tags, the [WM-If] tag controls what HTML will included into the generated page. The [WM-Else] tag is optional.

The tag arguments consist of two values compared by an operator. If the operator comparison evaluates to true, the HTML following the [WM-If] is written to the generated page. A space follows the operator, and everything after the operator is treated as the second value. If the comparison value is literal text, do not put quotes around it unless those quotes are present in your data.

If the optional [WM-Else] tag is used and the arguments evaluate to false, the HTML between the [WM-Else] and [/WM-If] tags will be written to the page instead.

Values can be any of the following:

  • Field: fieldName
    The contents of the field specified in fieldName in the current record being processed.
    Example: [WM-If: Field: ClientName .eq. David]

  • CurrentRecordNumber
    An internal WebMerge variable that contains the number of the current record being processed.
    Example: [WM-If: CurrentRecordNumber > 10]

  • CurrentRecordCount
    An internal WebMerge variable that contains the total number of records being processes in the current set.
    Example: [WM-If: CurrentRecordCount < 100]

  • IndexRecordNumber
    The number of the record as it appears on the current index page, useful when generating mutiple index pages.
    Example: [WM-If: IndexRecordNumber < 100]

  • Any String or Number
    WebMerge treats everything from the end of the operator to the closing right square bracket (minus leading blanks) as the comparison value. Don't enclose literal values in quotes. If you include quotes, they're treated as part of the comparison value. Literal values are not case-sensitive and can include spaces within text or number values.
    Example: [WM-If Field: FirstName = Steve]

  • The constant empty or ""
    WebMerge will let you note an empty value with either the word empty or simply two quotes with nothing between them.
    [WM-If: Field: Age = ""]
    [WM-If: Field: Age = empty]

  • len(Field: fieldName)
    Using the len ("length") function for a field value causes the operator to compare the number of characters of the data within the field specified in fieldname.

Operators make comparisons between the two values, and returns either true or false. Operators can be written in either of two forms: WebMerge supports the FileMaker form for operators as well as its own form which may be simpler to remember.

This table lists all operators in both supported forms:

WebMerge Form FMP Form Description Types
= .eq. equals All
<> .neq. does not equal All
> .gt. greater than number, date
>= .gte. greater than or equal to number, date
< .lt. less than number, date
<= .lte. less than or equal to number, date
contains .cn. contains string
DoesNotContain .ncn. does not contain string
IsIn .ii. is in string
IsNotIn .ini. is not in string
mod .mod. modulo number

The mod operator deserves a special note here, being perhaps the least obvious of the operators yet among the most valuable.

Mod simply determines whether there is a remainder when you divide the first value by the second. This is useful for determining a series of specific number of records, such as every fourth record or every tenth record.

For example if you wanted to have table cells created for each record by the WM-Record tag, but wanted every other record to have a different color, you could use mod to alternate portions of a WM-If tag like this:

[WM-If CurrentRecordNumber mod 2]
...even-numbered records are made from this HTML...
...odd-numbered records are made from this HTML...

By default, operators compare the two values as text unless both of them are numbers, in which case the comparison is performed numerically.

The mod operator is an exception to this rule, as it requires that both values are numbers, and will log an error if an attempt is made to apply it to textual data.

If you want to compare two values as dates, you can specify that the operator use a date comparison by adding ":date" to the operator:

[WM-If Field: BirthDate >:date 11/22/63]

Date values are evaluated according to the format in use on the computer WebMerge is running on. This format is set in the operating system's Date control panel.

Multiple Criteria

With WebMerge v2.4 and later you can specify multiple criteria for evaluation, with each criteria enclosed in parentheses:

 [WM-If: (Field: Age < 18) OR (Field: Age > 65)]

You can have up to 16 criteria, and can use parentheses to force some expressions to evaluate before others (as with alebra, expressions more deeply nested in parentheses will be evaluated first):

 [WM-If: ((Field: Age < 18) OR (Field: Age > 65))
   AND (Field: FrequentFlyer = true)]

Introduced in WebMerge 2.0.
Version 2.1 introduced the IndexRecordNumber value.
Version 2.4 introduced support for multiple evaluation criteria.
Version 2.5 introduced the len() function.