Conditional Branching
Useful when there are multiple choices
Preface
Branching using if action's pipeline and comparison operators - these operators don't need to be inside if branch. if statements always need to have an enclosing end.
Function
Case
Example
if
{{if (condition)}} output {{end}}
Initialization statement can also be inside if statement with conditional statement, limiting the initialized scope to that if statement.
{{$x := 24}}
{{if eq ($x := 42) 42}} Inside: {{$x}} {{end}}
Outside: {{$x}}
else if
{{if (condition)}} output1 {{else if (condition)}} output2 {{end}}
You can have as manyelse ifstatements as many different conditionals you have.
else
{{if (condition)}} output1 {{else}} output2 {{end}}
not
{{if not (condition)}} output {{end}}
and
{{if and (cond1) (cond2) (cond3)}} output {{end}}
or
{{if or (cond1) (cond2) (cond3)}} output {{end}}
Equal: eq
{{if eq .Channel.ID ########}} output {{end}}
Not equal: ne
{{$x := 7}} {{$y := 8}} {{ne $x $y}} returns true
Less than: lt
{{if lt (len .Args) 5}} output {{end}}
Less than or equal: le
{{$x := 7}} {{$y := 8}} {{le $x $y}} returns true
Greater than: gt
{{if gt (len .Args) 1}} output {{end}}
Greater than or equal: ge
{{$x := 7}} {{$y := 8}} {{ge $x $y}} returns false
When you use if-else functions, it will only execute the first one that matches the condition you want even if it matches multiple conditions. Example here.
Example:
It will only execute the first one that matches the condition you want.
If you write the codes like this, it will execute all parts.
You can also define the variable like the following one.
Last updated
Was this helpful?