Fusebox if/if verb

The first of two "helper" constructs for the Fusebox grammar is the conditional if /if. This is a straight forward way to provide branch logic within your application. Keep in mind that, all else being equal, you should strive to keep program logic in your fuses rather than your fuseactions. There are occasions, however, when it's clearer to do this in a fuseaction; hence the existence of this construct.

The if /if element takes one attribute, condition, that is required. It contains a statement that can be evaluated as stated by the script language being used for the core files to either true or false. The if /if construct also offers the sub-element tag pairs true /true and false /false. Both are optional and can contain Fusebox grammar instructions for what to do when the condition specified evaluates to true or false.

Here's an example of an if /if:

<if condition="listUsers.recordCount GT 0">
<true>
<xfa name="editUser" value="users.addEditUser" />
<include template="dspListUsers" />
</true>
<false>
<include template="dspNoRecordsFound.cfm" />
</false>
</if>

Notice that we can put any of the actual Fusebox grammar verbs inside the true and false tagset blocks. If you only wish to run code only when the condition is in a desired state (true or false), you can omit the unnecessary conditional. Here is code that is intended to run only when the stated condition is true.

<if condition="listUsers.recordCount GT 0">
<true>
<xfa name="editUser" value="users.addEditUser" />
<include template="dspListUsers" />
</true>
</if>

No false /false block is required. Similarly the true /true block can be omitted and it is legal to write:

<if condition="listUsers.recordCount GT 0">
<false>
<include template="dspNoRecordsFound.cfm" />
</false>
</if>

Note that in Fusebox 4 or 4.1 each true and false block cannot contain any additional nested ifs or loops (discussed in the next section). This is limitation is removed in Fusebox 5.

As we've reiterated several times you should however strive to put program logic in your fuses rather than your fuseactions whenever possible.

Nested Fusebox if Example

<if condition="listUsers.recordCount GT 0">
<true>
<xfa name="editUser" value="users.addEditUser" />
<if condition="Len(form.submit)">
<true>
<include template="actUpdateUser" />
</true>
</if>
<include template="dspListUsers" />
</true>
<false>
<include template="dspNoRecordsFound.cfm" />
</false>
</if>

XML compliant

Developers should note that XML imposes certain restriction on a small set of characters, requiring them to be specified via their character entities. This is noticeable with the ifverb since the common quote(") character is one such entity.

It is important to note that within your if condition logic, all quote characters (") must be converted to single quotes (').

Also if using the relocate verb, all ampersand characters (&) must be converted to their character code: &