361 users using DBSP now!
home -> documentation -> language reference -> IF tag


Description

Conditional statement that includes the delimited block if the specified condition is true, otherwise includes the block delimited by the optional ELSE tag.


Syntax

<#IF EXPRESSION="anexpression">
.
.
[ <#ELSE> ]
.
.
<#/IF>

EXPRESSION Specify in anexpression a boolean expression. The DBSP engine will evaluate the expression and the block inclusion will depend on this value. See the EXPRESSION property for more information about valid expressions.
ELSE The block delimited between the ELSE tag and the end of the if will be executed if and only if the expression evaluation returns false.

References

EXPRESSION
FOR
EXPVAL


Applications

The IF tag is one of the most important features of many languages, and DBSP is not the exception. This element allows the conditional execution of HTML code fragments. Moreover, IF tags can be nested indefinitely within other IF tags, which provides you with complete flexibility over conditional execution on your DSBP pages.


Examples

Example 1. Creating a common header for several pages.

The following example shows you how to create a header file and use it inside several pages.

Source code

examples/eif.dbsp


 
<#setcookie name="factor1" expression="1+5"/> 
 
<#setcookie name="factor2" expression="7-5"/> 
 
   <#if expression="factor1>factor2"> 
     the variable factor1 (<#factor1/>) is bigger than the variable factor2 (<#factor2/>)
   <#else>
     the variable factor1 (<#factor1/>) is smaller or same as the variable factor2 (<#factor1/>)
   <#/if>



Test example