Friday, July 1, 2011

Using conditional IF and IFNOT statements in BlueBox2.0 Tags

Today I decided to use my 'sharpening time' to get to grips with BB2.0 <!--:if and <!--:ifnot tags.

The basic syntax for these tags is:

<!--:if:{variable_name}{optional condition}:{action}:-->

This can be used as follows:


<!--:if:email:{print:Your email address is (#email#).}:-->

or

<!--:ifnot:email:{print:You do not have an email address.}:-->

This is fairly straightforward, the condition of the if and ifnot statements purely checks if a positive value exists for the variable and, if so, then it runs a sub-tag between the { }'s. This subtag is exactly the same as a normal BB2.0 tag, but, due to it's embedded nature, it gets { in place of <!--: and } in place of :-->. Also: you will notice that referring to the variable value within subtags you use the (# approach, by wrappinf the variable name in (# and #).

To up the ante a bit, I then decided to play with conditional statements like ==, !=, > and <. These work as follows:

<!--:if:email==bill@microsoft.com:{print:Hi Bill!}:-->

Note here that the value is never encapsulated in the ' and " string-wrappers normally used in code, and also that the condtional statement for 'equals' is double =.

Last thought on this, and this one stumped me for a while, is that when you are evaluating form-posted variables, remember to describe the variable name fully using the global|fields|variable_name method, eg:

<!--:if:global|fields|email==bill@microsoft.com:{print:Hi Bill!}:-->

No comments:

Post a Comment