If statements

In Dynamciweb HTML templates conditionals are a Dynamicweb specific syntax. In Razor conditionals are regular .NET syntax (C# or VB) and gives full programming capabilities against the template values. 

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

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

@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue) { text to print if condition is met } @If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue) { text to print if condition is met } else if [ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue) { text to print }
<!--@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-->

@if (GetString("TagName") == "Value") { text to print if condition is met } @if (GetInteger("TagName") == 123) { text to print if condition is met }
<!--@If(TagName==Value)--> text to print if condition is met <!--@EndIf-->

@if (GetString("TagName") != "Value") { text to print if condition is met } @if (GetInteger("TagName") != 123) { text to print if condition is met }

@if (GetString("TagName") == "Value") { text to print if condition is met } else if (GetString("TagName") == "Value") { text to print if condition is met } else { text to print }

  • 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='')
  • containsstartswith 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)
  • You can not use If... Else in If... Else.