Summary

You can use If and If...Else in all dynamicweb templates to make conditional statements. 

Supported operators:  

= and ==
<> and !=
<
>
>=
<=
||  (OR)
&&  (AND)
<contains> (Case insensitive)
<startswith> (Case insensitive)
<endswith> (Case insensitive)


Syntax:

<!--@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue)-->
    text to print if condition is met
<!--@EndIf-->
<!--@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue)-->
    text to print if condition is met
<--@Else-->
   text to print 
<!--@EndIf-->

Remarks

  • testvalue can be either numeric or text. Numerics are handled as doubles (except for contains, startswith and endswith). If testvalue is "" or '' it is parsed an empty string.
  • ' and " in testvalue are interpreted as text qualifiers and is basically not an option to test agains values containing ‘ and “. Example: If(SomeTag='')
  • Contains, startswith and endswith are case insensitive.
  • Unlimited nesting allowed (except when using Else - then no nesting allowed).
  • It's possible to compare template tags.
  • Example: If(DwPageID=Global:Page.Top.ID)
  • @Else is available from version 8.2.1.2.
  • Operators || (OR) and && (AND) are available from version 8.2.1.2.
  • You can not use If... Else in If... Else.

Examples

Example with > (larger than):

<!--@If(Ecom:Product.Price.Price>100)-->
- <!--@Ecom:Product.Name--> (Price: <!--@Ecom:Product.Price.Price-->)<br />
<!--@EndIf-->

Example with && (AND): 

<!--@If(Ecom:Product.Price.Price>100 && Ecom:Product.Name<startswith>'d')--> 
    - <!--@Ecom:Product.Name--> (Price: <!--@Ecom:Product.Price.Price-->)<br />
<!--@EndIf-->

Example with || (OR):

<!--@If(Ecom:Product.Price.Price>100 || Ecom:Product.Name<startswith>'d')--> 
    - <!--@Ecom:Product.Name--> (Price: <!--@Ecom:Product.Price.Price-->)<br />
<!--@EndIf-->
<!--@If(DwAreaID>1)--><!--@If(DwAreaID>1)-->

Example with || (OR), && (AND) and @Else:

<!--@If(DwAreaID=2)-->
    AreaID=2
<!--@Else-->
    ELSE: AreaID not 2
<!--@EndIf-->

<!--@If(DwAreaID=1)-->
    AreaID=1
<!--@Else-->
    ELSE: AreaID not 1
<!--@EndIf-->

<!--@If(DwAreaID=1)-->
    AreaID=1
<!--@EndIf-->


DwPageID: (<!--@DwPageID-->)

<!--@If(DwPageID=1||DwPageID=2)-->
    DwPageID=1 or DwPageID = 2
<!--@Else-->
    ELSE: DwPageID NOT 1 or 2
<!--@EndIf-->

DwPageID/AreaID: (<!--@DwPageID-->/<!--@DwAreaID-->)

<!--@If(DwPageID=1 && DwAreaID=1)-->
    DwPageID=1 and DwAreaID = 1
<!--@Else-->
    ELSE: DwPageID not 1 or DwAreaID not 1
<!--@EndIf-->

See more code examples

If statements