If conditions

If conditions can be used in the templates

{{ if true }}
    <h1>True</h1>
{{ else }}
    <h1>False</h1>
{{ end }}

Note that if condition comparison is type sensitive. If invalid types (types that cannot be compared) are given the template parser will break from that point onward.

Should always make sure that the types are comparable or cast them to comparable types before the condition check

<!-- Invalid, template will break from this point  -->
{{ if gt 1 "2" }}
{{ end }}

<!-- Valid -->
{{ if g1 1 (toInt "2") }}
{{ end }}

<!-- Valid, type cast from dynamic api result -->
{{ if g1 1 ($dynRes.Get "id").Int }}
{{ end }}

Available operators

  • eq - boolean truth of arg1 == arg2
  • ne - boolean truth of arg1 != arg2
  • lt - boolean truth of arg1 < arg2
  • le - boolean truth of arg1 <= arg2
  • gt - boolean truth of arg1 > arg2
  • ge - boolean truth of arg1 >= arg2
  • md - boolean truth of arg1 % arg2

Multiple conditions

Multiple conditions can also be described. There can be any number of conditions.

{{ if and (condition1) (condition2) }}
{{ end }}

For this we can use and & or. Use “()” to separate arguments.

{{ if and (or (condition1) (condition2)) (condition2) }}
{{ end }}

Sample

{{ if and (eq 1 2) (ne 3 4) }}
{{ end }}